summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
commit225aa1499e37faf9d38257caabbadc68d78b427e (patch)
tree102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs503
1 files changed, 503 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs b/Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs
new file mode 100644
index 0000000..a9fad65
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs
@@ -0,0 +1,503 @@
+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 System.Windows;
+using System.Windows.Controls;
+using ClosedXML.Excel;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+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.BI;
+
+public class ProspeccaoViewModel : BaseViewModel
+{
+ private readonly ProspeccaoServico _servico;
+
+ private PermissaoUsuario SelectedPermissaoUsuario;
+
+ private ObservableCollection<Vendedor> _vendedores;
+
+ private Vendedor _selectedVendedor = new Vendedor();
+
+ private List<string> _searchStatus = new List<string>
+ {
+ "TODOS",
+ ValidationHelper.GetDescription((Enum)(object)(StatusProspeccao)1),
+ ValidationHelper.GetDescription((Enum)(object)(StatusProspeccao)5),
+ ValidationHelper.GetDescription((Enum)(object)(StatusProspeccao)2),
+ ValidationHelper.GetDescription((Enum)(object)(StatusProspeccao)4),
+ ValidationHelper.GetDescription((Enum)(object)(StatusProspeccao)3)
+ };
+
+ private string _selectedStatusSearch = "AGENDANDO";
+
+ private StatusProspeccao? _selectedStatus;
+
+ private ObservableCollection<StatusDeProspeccao> _statusProspeccaoPersonalizado;
+
+ private DateTime _inicio = Funcoes.GetNetworkTime().Date;
+
+ private DateTime _fim = Funcoes.GetNetworkTime().Date.AddDays(7.0);
+
+ private ObservableCollection<Prospeccao> _prospeccoesFiltradas;
+
+ private Prospeccao _selectedProspeccao;
+
+ private ObservableCollection<Prospeccao> _prospeccao;
+
+ private bool _naoHaDados;
+
+ public ObservableCollection<Vendedor> Vendedores
+ {
+ get
+ {
+ return _vendedores;
+ }
+ set
+ {
+ _vendedores = value;
+ OnPropertyChanged("Vendedores");
+ }
+ }
+
+ public Vendedor SelectedVendedor
+ {
+ get
+ {
+ return _selectedVendedor;
+ }
+ set
+ {
+ _selectedVendedor = value;
+ OnPropertyChanged("SelectedVendedor");
+ }
+ }
+
+ public List<string> SearchStatus
+ {
+ get
+ {
+ return _searchStatus;
+ }
+ set
+ {
+ _searchStatus = value;
+ SelectedStatusSearch = value[1];
+ OnPropertyChanged("SearchStatus");
+ }
+ }
+
+ public string SelectedStatusSearch
+ {
+ get
+ {
+ return _selectedStatusSearch;
+ }
+ set
+ {
+ _selectedStatusSearch = value;
+ switch (value)
+ {
+ default:
+ SelectedStatus = null;
+ break;
+ case "AGENDADO":
+ SelectedStatus = (StatusProspeccao)1;
+ break;
+ case "GANHO":
+ SelectedStatus = (StatusProspeccao)2;
+ break;
+ case "PERDIDO":
+ SelectedStatus = (StatusProspeccao)3;
+ break;
+ case "NÃO TRABALHADO":
+ SelectedStatus = (StatusProspeccao)4;
+ break;
+ case "EM ANDAMENTO":
+ SelectedStatus = (StatusProspeccao)5;
+ break;
+ }
+ OnPropertyChanged("SelectedStatusSearch");
+ }
+ }
+
+ public StatusProspeccao? SelectedStatus
+ {
+ get
+ {
+ return _selectedStatus;
+ }
+ set
+ {
+ _selectedStatus = value;
+ OnPropertyChanged("SelectedStatus");
+ }
+ }
+
+ public ObservableCollection<StatusDeProspeccao> StatusProspeccaoPersonalizado
+ {
+ get
+ {
+ return _statusProspeccaoPersonalizado;
+ }
+ set
+ {
+ _statusProspeccaoPersonalizado = value;
+ OnPropertyChanged("StatusProspeccaoPersonalizado");
+ }
+ }
+
+ public DateTime Inicio
+ {
+ get
+ {
+ return _inicio;
+ }
+ set
+ {
+ _inicio = value;
+ OnPropertyChanged("Inicio");
+ }
+ }
+
+ public DateTime Fim
+ {
+ get
+ {
+ return _fim;
+ }
+ set
+ {
+ _fim = value;
+ OnPropertyChanged("Fim");
+ }
+ }
+
+ public List<Prospeccao> Prospeccoes { get; set; }
+
+ public ObservableCollection<Prospeccao> ProspeccoesFiltradas
+ {
+ get
+ {
+ return _prospeccoesFiltradas;
+ }
+ set
+ {
+ _prospeccoesFiltradas = value;
+ OnPropertyChanged("ProspeccoesFiltradas");
+ }
+ }
+
+ public Prospeccao SelectedProspeccao
+ {
+ get
+ {
+ return _selectedProspeccao;
+ }
+ set
+ {
+ _selectedProspeccao = value;
+ OnPropertyChanged("SelectedProspeccao");
+ }
+ }
+
+ public AutoCompleteFilterPredicate<object> ProspeccaoItemFilter => (string searchText, object obj) => ((Prospeccao)obj).Nome.ToUpper().Contains(searchText.ToUpper()) || ((Prospeccao)obj).Documento.ToString().ToUpper().Contains(searchText.ToUpper()) || ((Prospeccao)obj).Telefone1.ToString().ToUpper().Contains(searchText.ToUpper()) || ((Prospeccao)obj).Telefone2.ToString().ToUpper().Contains(searchText.ToUpper()) || ((Prospeccao)obj).Email.ToString().ToUpper().Contains(searchText.ToUpper()) || ((Prospeccao)obj).VigenciaFinal.ToString().ToUpper().Contains(searchText.ToUpper());
+
+ public ObservableCollection<Prospeccao> Prospeccao
+ {
+ get
+ {
+ return _prospeccao;
+ }
+ set
+ {
+ _prospeccao = value;
+ NaoHaDados = value == null || value.Count == 0;
+ OnPropertyChanged("Prospeccao");
+ }
+ }
+
+ public bool NaoHaDados
+ {
+ get
+ {
+ return _naoHaDados;
+ }
+ set
+ {
+ _naoHaDados = value;
+ OnPropertyChanged("NaoHaDados");
+ }
+ }
+
+ public ProspeccaoViewModel()
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000b: Expected O, but got Unknown
+ _servico = new ProspeccaoServico();
+ StatusProspeccaoPersonalizado = new ObservableCollection<StatusDeProspeccao>(Recursos.StatusProspeccao.Where((StatusDeProspeccao x) => x.Ativo).ToList());
+ CarregaVendedores();
+ SelectedStatusSearch = SearchStatus[1];
+ CarregaProspeccoes();
+ }
+
+ public async void Excluir(Prospeccao prospeccao)
+ {
+ if (!(await BuscaPermissao("Excluir")) || prospeccao == null)
+ {
+ return;
+ }
+ bool flag = prospeccao.Tarefa == null;
+ if (flag)
+ {
+ flag = !(await ShowMessage("DESEJA EXCLUIR ESSA PROSPECÇÃO?", "SIM", "NÃO"));
+ }
+ bool flag2 = flag;
+ if (!flag2)
+ {
+ bool flag3 = prospeccao.Tarefa != null;
+ if (flag3)
+ {
+ flag3 = !(await ShowMessage("HÁ UMA TAREFA ANEXADA A ESSA PROSPECÇÃO. ESSE PROCEDIMENTO IRÁ EXCLUIR A TAREFA ANEXADA." + Environment.NewLine + "DESEJA REALMENTE PROSSEGUIR?", "SIM", "NÃO"));
+ }
+ flag2 = flag3;
+ }
+ if (!flag2 && await _servico.Delete(prospeccao))
+ {
+ RegistrarAcao($"EXCLUIU PROSPECÇÃO DO ID: {((DomainBase)prospeccao).Id}", ((DomainBase)prospeccao).Id, (TipoTela)33, $"CLIENTE \"{prospeccao.Nome}\", ID: {((DomainBase)prospeccao).Id}");
+ await CarregarProspeccoes();
+ ToggleSnackBar("PROSPECÇÃO EXCLUÍDA COM SUCESSO");
+ }
+ }
+
+ public async void CarregaProspeccoes()
+ {
+ await CarregarProspeccoes();
+ }
+
+ public async void CarregaVendedores()
+ {
+ await CarregarVendedores();
+ }
+
+ public async Task CarregarVendedores()
+ {
+ List<long> vinculos = (await new VendedorUsuarioServico().FindByVinculo(Recursos.Usuario)).Select((VendedorUsuario x) => ((DomainBase)x.Vendedor).Id).ToList();
+ List<Vendedor> list = new List<Vendedor>();
+ if (vinculos.Count > 0 && !Recursos.Usuario.Administrador)
+ {
+ list.AddRange((from x in Recursos.Vendedores
+ where (Recursos.Usuario.IdEmpresa == 1 || x.IdEmpresa == Recursos.Usuario.IdEmpresa) && x.Ativo && vinculos.Contains(((DomainBase)x).Id)
+ orderby x.Nome
+ select x).ToList());
+ }
+ else
+ {
+ list.Add(new Vendedor
+ {
+ Id = 0L,
+ Nome = "TODOS OS VENDEDORES"
+ });
+ list.AddRange((from x in Recursos.Vendedores
+ where (Recursos.Usuario.IdEmpresa == 1 || x.IdEmpresa == Recursos.Usuario.IdEmpresa) && x.Ativo
+ orderby x.Nome
+ select x).ToList());
+ }
+ Vendedores = new ObservableCollection<Vendedor>(list);
+ SelectedVendedor = Vendedores.FirstOrDefault();
+ }
+
+ public async Task CarregarProspeccoes()
+ {
+ if (!(Inicio > Fim))
+ {
+ Loading(isLoading: true);
+ base.IsVisible = (Visibility)2;
+ Prospeccoes = await _servico.BuscarProspeccoes(((DomainBase)SelectedVendedor).Id, Inicio, Fim, SelectedStatus);
+ ProspeccoesFiltradas = new ObservableCollection<Prospeccao>(Prospeccoes.OrderBy((Prospeccao x) => x.VigenciaFinal));
+ SelectedProspeccao = ProspeccoesFiltradas.FirstOrDefault();
+ base.IsVisible = (Visibility)0;
+ Loading(isLoading: false);
+ }
+ }
+
+ internal async Task<List<Prospeccao>> FiltrarProspecao(string value)
+ {
+ return await Task.Run(() => Filtrar(value));
+ }
+
+ public List<Prospeccao> Filtrar(string filter)
+ {
+ if (Prospeccoes == null)
+ {
+ return null;
+ }
+ ProspeccoesFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Prospeccao>(Prospeccoes) : new ObservableCollection<Prospeccao>(from x in Prospeccoes
+ where ValidationHelper.RemoveDiacritics(ValidationHelper.RemoveDiacritics(x.Nome).ToUpper().Trim()).Contains(filter) || (x.Documento != null && ValidationHelper.RemoveDiacritics(x.Documento.Trim()).Contains(filter)) || (x.Telefone1 != null && ValidationHelper.RemoveDiacritics(x.Telefone1.Trim()).Contains(filter)) || (x.Telefone2 != null && ValidationHelper.RemoveDiacritics(x.Telefone2.Trim()).Contains(filter)) || (x.Email != null && ValidationHelper.RemoveDiacritics(x.Email.Trim()).Contains(filter)) || (x.VigenciaFinal.HasValue && ValidationHelper.RemoveDiacritics(x.VigenciaFinal.ToString().Trim()).Contains(filter))
+ orderby x.VigenciaFinal
+ select x));
+ return ProspeccoesFiltradas.ToList();
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar(Prospeccao prospecao)
+ {
+ return await SalvarProspeccao(prospecao);
+ }
+
+ public async Task Print()
+ {
+ if (ProspeccoesFiltradas != null)
+ {
+ List<ProspeccaoToPrint> printProspect = new List<ProspeccaoToPrint>();
+ ProspeccoesFiltradas.AsEnumerable().ToList().ForEach(delegate(Prospeccao x)
+ {
+ //IL_0000: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0005: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0011: 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_0032: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0047: Unknown result type (might be due to invalid IL or missing references)
+ //IL_005c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0071: Unknown result type (might be due to invalid IL or missing references)
+ //IL_007d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0092: Unknown result type (might be due to invalid IL or missing references)
+ //IL_009e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00be: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00d3: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00e9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00f6: Expected O, but got Unknown
+ ProspeccaoToPrint item = new ProspeccaoToPrint
+ {
+ Nome = x.Nome,
+ Documento = (x.Documento ?? ""),
+ Nascimento = x.Nascimento,
+ Prefixo1 = (x.Prefixo1 ?? ""),
+ Telefone1 = (x.Telefone1 ?? ""),
+ Email = (x.Email ?? ""),
+ VigenciaFinal = x.VigenciaFinal,
+ Item = (x.Item ?? ""),
+ Status = x.Status,
+ StatusPersonalizadotoPrint = ((x.StatusPersonalizado == null) ? "" : x.StatusPersonalizado.Nome),
+ Tipo = (x.Tipo ?? ""),
+ Vendedor = (x.Vendedor.Nome ?? null),
+ Valor = x.Valor
+ };
+ printProspect.Add(item);
+ });
+ printProspect = printProspect.OrderBy((ProspeccaoToPrint x) => x.Vendedor).ToList();
+ string text = await Funcoes.GenerateTable(printProspect.ToList(), new List<string>());
+ if (!string.IsNullOrEmpty(text))
+ {
+ text = Funcoes.ExportarHtml(new TipoRelatorio
+ {
+ Inicio = Inicio,
+ Fim = Fim,
+ Nome = "PROSPECÇÕES - " + SelectedVendedor.Nome
+ }, text, "60", "landscaoe");
+ string tempPath = Path.GetTempPath();
+ string text2 = $"{tempPath}PROSPECÇÃO_{Funcoes.GetNetworkTime():ddMMyyyyhhmmss}.html";
+ StreamWriter streamWriter = new StreamWriter(text2, append: true, Encoding.UTF8);
+ streamWriter.Write(text);
+ streamWriter.Close();
+ Process.Start(text2);
+ }
+ }
+ }
+
+ public async Task GerarExcel()
+ {
+ if (ProspeccoesFiltradas == null)
+ {
+ ShowMessage("NÃO HÁ DADOS PARA A IMPRESSÃO EM EXCEL");
+ return;
+ }
+ List<ProspeccaoToPrint> excelProspect = new List<ProspeccaoToPrint>();
+ ProspeccoesFiltradas.AsEnumerable().ToList().ForEach(delegate(Prospeccao x)
+ {
+ //IL_0000: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0005: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0011: 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_0032: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0047: Unknown result type (might be due to invalid IL or missing references)
+ //IL_005c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0071: Unknown result type (might be due to invalid IL or missing references)
+ //IL_007d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0092: Unknown result type (might be due to invalid IL or missing references)
+ //IL_009e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00be: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00d3: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00e9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00f6: Expected O, but got Unknown
+ ProspeccaoToPrint item = new ProspeccaoToPrint
+ {
+ Nome = x.Nome,
+ Documento = (x.Documento ?? ""),
+ Nascimento = x.Nascimento,
+ Prefixo1 = (x.Prefixo1 ?? ""),
+ Telefone1 = (x.Telefone1 ?? ""),
+ Email = (x.Email ?? ""),
+ VigenciaFinal = x.VigenciaFinal,
+ Item = (x.Item ?? ""),
+ Status = x.Status,
+ StatusPersonalizadotoPrint = ((x.StatusPersonalizado == null) ? "" : x.StatusPersonalizado.Nome),
+ Tipo = (x.Tipo ?? ""),
+ Vendedor = (x.Vendedor.Nome ?? null),
+ Valor = x.Valor
+ };
+ excelProspect.Add(item);
+ });
+ string tempPath = Path.GetTempPath();
+ string fileName = $"{tempPath}{Guid.NewGuid()}.xlsx";
+ XLWorkbook val = new XLWorkbook();
+ string nome = "PROSPECÇÃO";
+ (await Funcoes.GerarXls(val, nome, excelProspect, new List<string>())).SaveAs(fileName);
+ Process.Start(fileName);
+ }
+
+ public async Task CarregaProspeccao()
+ {
+ if (ProspeccoesFiltradas != null)
+ {
+ ProspeccoesFiltradas = new ObservableCollection<Prospeccao>(ProspeccoesFiltradas.ToList());
+ }
+ }
+
+ public async Task CarregarPermissao()
+ {
+ SelectedPermissaoUsuario = await ServicoPermissUsuario.VerificarPermissao(Recursos.Usuario, (TipoTela)60);
+ }
+
+ public async Task<bool> BuscaPermissao(string Tipo)
+ {
+ if (Recursos.Usuario.Administrador)
+ {
+ return true;
+ }
+ if (Tipo == "Alterar" && SelectedPermissaoUsuario != null && !SelectedPermissaoUsuario.Alterar)
+ {
+ return false;
+ }
+ if (Tipo == "Excluir" && SelectedPermissaoUsuario != null && !SelectedPermissaoUsuario.Excluir)
+ {
+ return false;
+ }
+ if (Tipo == "Incluir" && SelectedPermissaoUsuario != null && !SelectedPermissaoUsuario.Incluir)
+ {
+ return false;
+ }
+ return true;
+ }
+}