summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.BI/ProspeccaoViewModel.cs
blob: a9fad65e6f7d9ed941ad183862da8ffceea8a0e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
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;
	}
}