summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels/DashboardViewModel.cs
blob: be683d21687f76d31789323e135acae4eef4b945 (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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
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;
	}
}