From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../ViewModels/BI/ProspeccaoViewModel.cs | 553 +++++++++++++++++++++ 1 file changed, 553 insertions(+) create mode 100644 Gestor.Application/ViewModels/BI/ProspeccaoViewModel.cs (limited to 'Gestor.Application/ViewModels/BI/ProspeccaoViewModel.cs') diff --git a/Gestor.Application/ViewModels/BI/ProspeccaoViewModel.cs b/Gestor.Application/ViewModels/BI/ProspeccaoViewModel.cs new file mode 100644 index 0000000..4839d95 --- /dev/null +++ b/Gestor.Application/ViewModels/BI/ProspeccaoViewModel.cs @@ -0,0 +1,553 @@ +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; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace Gestor.Application.ViewModels.BI +{ + public class ProspeccaoViewModel : BaseViewModel + { + private readonly ProspeccaoServico _servico; + + private PermissaoUsuario SelectedPermissaoUsuario; + + private ObservableCollection _vendedores; + + private Vendedor _selectedVendedor = new Vendedor(); + + private List _searchStatus = new List() + { + "TODOS", + ValidationHelper.GetDescription((StatusProspeccao)1), + ValidationHelper.GetDescription((StatusProspeccao)5), + ValidationHelper.GetDescription((StatusProspeccao)2), + ValidationHelper.GetDescription((StatusProspeccao)4), + ValidationHelper.GetDescription((StatusProspeccao)3) + }; + + private string _selectedStatusSearch = "AGENDANDO"; + + private StatusProspeccao? _selectedStatus; + + private ObservableCollection _statusProspeccaoPersonalizado; + + private DateTime _inicio = Funcoes.GetNetworkTime().Date; + + private DateTime _fim = Funcoes.GetNetworkTime().Date.AddDays(7); + + private ObservableCollection _prospeccoesFiltradas; + + private Gestor.Model.Domain.Seguros.Prospeccao _selectedProspeccao; + + private ObservableCollection _prospeccao; + + private bool _naoHaDados; + + public DateTime Fim + { + get + { + return this._fim; + } + set + { + this._fim = value; + base.OnPropertyChanged("Fim"); + } + } + + public DateTime Inicio + { + get + { + return this._inicio; + } + set + { + this._inicio = value; + base.OnPropertyChanged("Inicio"); + } + } + + public bool NaoHaDados + { + get + { + return this._naoHaDados; + } + set + { + this._naoHaDados = value; + base.OnPropertyChanged("NaoHaDados"); + } + } + + public ObservableCollection Prospeccao + { + get + { + return this._prospeccao; + } + set + { + this._prospeccao = value; + this.NaoHaDados = (value == null ? true : value.Count == 0); + base.OnPropertyChanged("Prospeccao"); + } + } + + public AutoCompleteFilterPredicate ProspeccaoItemFilter + { + get + { + AutoCompleteFilterPredicate u003cu003e9_530 = ProspeccaoViewModel.u003cu003ec.u003cu003e9__53_0; + if (u003cu003e9_530 == null) + { + u003cu003e9_530 = new AutoCompleteFilterPredicate(ProspeccaoViewModel.u003cu003ec.u003cu003e9, (string searchText, object obj) => { + if (((Gestor.Model.Domain.Seguros.Prospeccao)obj).get_Nome().ToUpper().Contains(searchText.ToUpper()) || ((Gestor.Model.Domain.Seguros.Prospeccao)obj).get_Documento().ToString().ToUpper().Contains(searchText.ToUpper()) || ((Gestor.Model.Domain.Seguros.Prospeccao)obj).get_Telefone1().ToString().ToUpper().Contains(searchText.ToUpper()) || ((Gestor.Model.Domain.Seguros.Prospeccao)obj).get_Telefone2().ToString().ToUpper().Contains(searchText.ToUpper()) || ((Gestor.Model.Domain.Seguros.Prospeccao)obj).get_Email().ToString().ToUpper().Contains(searchText.ToUpper())) + { + return true; + } + return ((Gestor.Model.Domain.Seguros.Prospeccao)obj).get_VigenciaFinal().ToString().ToUpper().Contains(searchText.ToUpper()); + }); + ProspeccaoViewModel.u003cu003ec.u003cu003e9__53_0 = u003cu003e9_530; + } + return u003cu003e9_530; + } + } + + public List Prospeccoes + { + get; + set; + } + + public ObservableCollection ProspeccoesFiltradas + { + get + { + return this._prospeccoesFiltradas; + } + set + { + this._prospeccoesFiltradas = value; + base.OnPropertyChanged("ProspeccoesFiltradas"); + } + } + + public List SearchStatus + { + get + { + return this._searchStatus; + } + set + { + this._searchStatus = value; + this.SelectedStatusSearch = value[1]; + base.OnPropertyChanged("SearchStatus"); + } + } + + public Gestor.Model.Domain.Seguros.Prospeccao SelectedProspeccao + { + get + { + return this._selectedProspeccao; + } + set + { + this._selectedProspeccao = value; + base.OnPropertyChanged("SelectedProspeccao"); + } + } + + public StatusProspeccao? SelectedStatus + { + get + { + return this._selectedStatus; + } + set + { + this._selectedStatus = value; + base.OnPropertyChanged("SelectedStatus"); + } + } + + public string SelectedStatusSearch + { + get + { + return this._selectedStatusSearch; + } + set + { + this._selectedStatusSearch = value; + if (value == "AGENDADO") + { + this.SelectedStatus = new StatusProspeccao?(1); + } + else if (value == "GANHO") + { + this.SelectedStatus = new StatusProspeccao?(2); + } + else if (value == "PERDIDO") + { + this.SelectedStatus = new StatusProspeccao?(3); + } + else if (value == "NÃO TRABALHADO") + { + this.SelectedStatus = new StatusProspeccao?(4); + } + else if (value == "EM ANDAMENTO") + { + this.SelectedStatus = new StatusProspeccao?(5); + } + else + { + this.SelectedStatus = null; + } + base.OnPropertyChanged("SelectedStatusSearch"); + } + } + + public Vendedor SelectedVendedor + { + get + { + return this._selectedVendedor; + } + set + { + this._selectedVendedor = value; + base.OnPropertyChanged("SelectedVendedor"); + } + } + + public ObservableCollection StatusProspeccaoPersonalizado + { + get + { + return this._statusProspeccaoPersonalizado; + } + set + { + this._statusProspeccaoPersonalizado = value; + base.OnPropertyChanged("StatusProspeccaoPersonalizado"); + } + } + + public ObservableCollection Vendedores + { + get + { + return this._vendedores; + } + set + { + this._vendedores = value; + base.OnPropertyChanged("Vendedores"); + } + } + + public ProspeccaoViewModel() + { + this._servico = new ProspeccaoServico(); + this.StatusProspeccaoPersonalizado = new ObservableCollection(( + from x in Recursos.StatusProspeccao + where x.get_Ativo() + select x).ToList()); + this.CarregaVendedores(); + this.SelectedStatusSearch = this.SearchStatus[1]; + this.CarregaProspeccoes(); + } + + public async Task BuscaPermissao(string Tipo) + { + bool flag; + ProspeccaoViewModel prospeccaoViewModel = this; + if (Recursos.Usuario.get_Administrador()) + { + flag = true; + } + else if (Tipo == "Alterar" && prospeccaoViewModel.SelectedPermissaoUsuario != null && !prospeccaoViewModel.SelectedPermissaoUsuario.get_Alterar()) + { + flag = false; + } + else if (!(Tipo == "Excluir") || prospeccaoViewModel.SelectedPermissaoUsuario == null || prospeccaoViewModel.SelectedPermissaoUsuario.get_Excluir()) + { + flag = (!(Tipo == "Incluir") || prospeccaoViewModel.SelectedPermissaoUsuario == null || prospeccaoViewModel.SelectedPermissaoUsuario.get_Incluir() ? true : false); + } + else + { + flag = false; + } + return flag; + } + + public async Task CarregaProspeccao() + { + ProspeccaoViewModel observableCollection = this; + if (observableCollection.ProspeccoesFiltradas != null) + { + observableCollection.ProspeccoesFiltradas = new ObservableCollection(observableCollection.ProspeccoesFiltradas.ToList()); + } + } + + public async void CarregaProspeccoes() + { + await this.CarregarProspeccoes(); + } + + public async Task CarregarPermissao() + { + this.SelectedPermissaoUsuario = await this.ServicoPermissUsuario.VerificarPermissao(Recursos.Usuario, 60); + } + + public async Task CarregarProspeccoes() + { + if (this.Inicio <= this.Fim) + { + base.Loading(true); + base.IsVisible = Visibility.Collapsed; + this.Prospeccoes = await this._servico.BuscarProspeccoes(this.SelectedVendedor.get_Id(), this.Inicio, this.Fim, this.SelectedStatus); + ProspeccaoViewModel observableCollection = this; + List prospeccoes = this.Prospeccoes; + observableCollection.ProspeccoesFiltradas = new ObservableCollection( + from x in prospeccoes + orderby x.get_VigenciaFinal() + select x); + this.SelectedProspeccao = this.ProspeccoesFiltradas.FirstOrDefault(); + base.IsVisible = Visibility.Visible; + base.Loading(false); + } + } + + public async Task CarregarVendedores() + { + List vendedorUsuarios = await (new VendedorUsuarioServico()).FindByVinculo(Recursos.Usuario); + List list = ( + from x in vendedorUsuarios + select x.get_Vendedor().get_Id()).ToList(); + List vendedors = new List(); + if (list.Count <= 0 || Recursos.Usuario.get_Administrador()) + { + Vendedor vendedor = new Vendedor(); + vendedor.set_Id((long)0); + vendedor.set_Nome("TODOS OS VENDEDORES"); + vendedors.Add(vendedor); + List vendedors1 = vendedors; + List vendedores = Recursos.Vendedores; + IEnumerable vendedors2 = vendedores.Where((Vendedor x) => { + if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa()) + { + return false; + } + return x.get_Ativo(); + }); + vendedors1.AddRange(( + from x in vendedors2 + orderby x.get_Nome() + select x).ToList()); + } + else + { + List vendedors3 = vendedors; + IEnumerable vendedors4 = Recursos.Vendedores.Where((Vendedor x) => { + if (Recursos.Usuario.get_IdEmpresa() != (long)1 && x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa() || !x.get_Ativo()) + { + return false; + } + return list.Contains(x.get_Id()); + }); + vendedors3.AddRange(( + from x in vendedors4 + orderby x.get_Nome() + select x).ToList()); + } + this.Vendedores = new ObservableCollection(vendedors); + this.SelectedVendedor = this.Vendedores.FirstOrDefault(); + } + + public async void CarregaVendedores() + { + await this.CarregarVendedores(); + } + + public async void Excluir(Gestor.Model.Domain.Seguros.Prospeccao prospeccao) + { + if (await this.BuscaPermissao("Excluir")) + { + if (prospeccao != null) + { + bool tarefa = prospeccao.get_Tarefa() == null; + if (tarefa) + { + tarefa = !await base.ShowMessage("DESEJA EXCLUIR ESSA PROSPECÇÃO?", "SIM", "NÃO", false); + } + bool flag = tarefa; + if (!flag) + { + bool tarefa1 = prospeccao.get_Tarefa() != null; + if (tarefa1) + { + tarefa1 = !await base.ShowMessage(string.Concat("HÁ UMA TAREFA ANEXADA A ESSA PROSPECÇÃO. ESSE PROCEDIMENTO IRÁ EXCLUIR A TAREFA ANEXADA.", Environment.NewLine, "DESEJA REALMENTE PROSSEGUIR?"), "SIM", "NÃO", false); + } + flag = tarefa1; + } + if (!flag) + { + if (await this._servico.Delete(prospeccao)) + { + base.RegistrarAcao(string.Format("EXCLUIU PROSPECÇÃO DO ID: {0}", prospeccao.get_Id()), prospeccao.get_Id(), new TipoTela?(33), string.Format("CLIENTE \"{0}\", ID: {1}", prospeccao.get_Nome(), prospeccao.get_Id())); + await this.CarregarProspeccoes(); + base.ToggleSnackBar("PROSPECÇÃO EXCLUÍDA COM SUCESSO", true); + } + } + } + } + } + + public List Filtrar(string filter) + { + if (this.Prospeccoes == null) + { + return null; + } + this.ProspeccoesFiltradas = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(this.Prospeccoes) : new ObservableCollection(this.Prospeccoes.Where((Gestor.Model.Domain.Seguros.Prospeccao x) => { + if (ValidationHelper.RemoveDiacritics(ValidationHelper.RemoveDiacritics(x.get_Nome()).ToUpper().Trim()).Contains(filter) || x.get_Documento() != null && ValidationHelper.RemoveDiacritics(x.get_Documento().Trim()).Contains(filter) || x.get_Telefone1() != null && ValidationHelper.RemoveDiacritics(x.get_Telefone1().Trim()).Contains(filter) || x.get_Telefone2() != null && ValidationHelper.RemoveDiacritics(x.get_Telefone2().Trim()).Contains(filter) || x.get_Email() != null && ValidationHelper.RemoveDiacritics(x.get_Email().Trim()).Contains(filter)) + { + return true; + } + if (!x.get_VigenciaFinal().HasValue) + { + return false; + } + return ValidationHelper.RemoveDiacritics(x.get_VigenciaFinal().ToString().Trim()).Contains(filter); + }).OrderBy((Gestor.Model.Domain.Seguros.Prospeccao x) => x.get_VigenciaFinal()))); + return this.ProspeccoesFiltradas.ToList(); + } + + internal async Task> FiltrarProspecao(string value) + { + List prospeccaos = await Task.Run>(() => this.Filtrar(value)); + return prospeccaos; + } + + public async Task GerarExcel() + { + string str; + if (this.ProspeccoesFiltradas != null) + { + List prospeccaoToPrints = new List(); + this.ProspeccoesFiltradas.AsEnumerable().ToList().ForEach((Gestor.Model.Domain.Seguros.Prospeccao x) => { + ProspeccaoToPrint prospeccaoToPrint = new ProspeccaoToPrint(); + prospeccaoToPrint.set_Nome(x.get_Nome()); + prospeccaoToPrint.set_Documento(x.get_Documento() ?? ""); + prospeccaoToPrint.set_Nascimento(x.get_Nascimento()); + prospeccaoToPrint.set_Prefixo1(x.get_Prefixo1() ?? ""); + prospeccaoToPrint.set_Telefone1(x.get_Telefone1() ?? ""); + prospeccaoToPrint.set_Email(x.get_Email() ?? ""); + prospeccaoToPrint.set_VigenciaFinal(x.get_VigenciaFinal()); + prospeccaoToPrint.set_Item(x.get_Item() ?? ""); + prospeccaoToPrint.set_Status(x.get_Status()); + prospeccaoToPrint.set_StatusPersonalizadotoPrint((x.get_StatusPersonalizado() == null ? "" : x.get_StatusPersonalizado().get_Nome())); + prospeccaoToPrint.set_Tipo(x.get_Tipo() ?? ""); + object nome = x.get_Vendedor().get_Nome(); + if (nome == null) + { + nome = null; + } + prospeccaoToPrint.set_Vendedor((string)nome); + prospeccaoToPrint.set_Valor(x.get_Valor()); + prospeccaoToPrints.Add(prospeccaoToPrint); + }); + string tempPath = ""; + str = ""; + tempPath = Path.GetTempPath(); + str = string.Format("{0}{1}.xlsx", tempPath, Guid.NewGuid()); + string str1 = "PROSPECÇÃO"; + await Funcoes.GerarXls(new XLWorkbook(), str1, prospeccaoToPrints, new List()).SaveAs(str); + Process.Start(str); + } + else + { + base.ShowMessage("NÃO HÁ DADOS PARA A IMPRESSÃO EM EXCEL", "OK", "", false); + } + str = null; + } + + public async Task Print() + { + if (this.ProspeccoesFiltradas != null) + { + List prospeccaoToPrints = new List(); + this.ProspeccoesFiltradas.AsEnumerable().ToList().ForEach((Gestor.Model.Domain.Seguros.Prospeccao x) => { + ProspeccaoToPrint prospeccaoToPrint = new ProspeccaoToPrint(); + prospeccaoToPrint.set_Nome(x.get_Nome()); + prospeccaoToPrint.set_Documento(x.get_Documento() ?? ""); + prospeccaoToPrint.set_Nascimento(x.get_Nascimento()); + prospeccaoToPrint.set_Prefixo1(x.get_Prefixo1() ?? ""); + prospeccaoToPrint.set_Telefone1(x.get_Telefone1() ?? ""); + prospeccaoToPrint.set_Email(x.get_Email() ?? ""); + prospeccaoToPrint.set_VigenciaFinal(x.get_VigenciaFinal()); + prospeccaoToPrint.set_Item(x.get_Item() ?? ""); + prospeccaoToPrint.set_Status(x.get_Status()); + prospeccaoToPrint.set_StatusPersonalizadotoPrint((x.get_StatusPersonalizado() == null ? "" : x.get_StatusPersonalizado().get_Nome())); + prospeccaoToPrint.set_Tipo(x.get_Tipo() ?? ""); + object nome = x.get_Vendedor().get_Nome(); + if (nome == null) + { + nome = null; + } + prospeccaoToPrint.set_Vendedor((string)nome); + prospeccaoToPrint.set_Valor(x.get_Valor()); + prospeccaoToPrints.Add(prospeccaoToPrint); + }); + List prospeccaoToPrints1 = prospeccaoToPrints; + prospeccaoToPrints = ( + from x in prospeccaoToPrints1 + orderby x.get_Vendedor() + select x).ToList(); + string str = await Funcoes.GenerateTable(prospeccaoToPrints.ToList(), new List(), false, false, "", null); + if (!string.IsNullOrEmpty(str)) + { + TipoRelatorio tipoRelatorio = new TipoRelatorio(); + tipoRelatorio.set_Inicio(this.Inicio); + tipoRelatorio.set_Fim(this.Fim); + tipoRelatorio.set_Nome(string.Concat("PROSPECÇÕES - ", this.SelectedVendedor.get_Nome())); + str = Funcoes.ExportarHtml(tipoRelatorio, str, "60", "landscaoe", false, ""); + string tempPath = Path.GetTempPath(); + string str1 = string.Format("{0}PROSPECÇÃO_{1:ddMMyyyyhhmmss}.html", tempPath, Funcoes.GetNetworkTime()); + StreamWriter streamWriter = new StreamWriter(str1, true, Encoding.UTF8); + streamWriter.Write(str); + streamWriter.Close(); + Process.Start(str1); + } + } + } + + public async Task>> Salvar(Gestor.Model.Domain.Seguros.Prospeccao prospecao) + { + return await base.SalvarProspeccao(prospecao); + } + } +} \ No newline at end of file -- cgit v1.2.3