summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Comissao/ComissaoViewModel.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.Comissao/ComissaoViewModel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Comissao/ComissaoViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Comissao/ComissaoViewModel.cs2497
1 files changed, 2497 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Comissao/ComissaoViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Comissao/ComissaoViewModel.cs
new file mode 100644
index 0000000..f79267f
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels.Comissao/ComissaoViewModel.cs
@@ -0,0 +1,2497 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+using CsQuery.ExtensionMethods;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.Servicos.Seguros;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Infrastructure.Helpers;
+using Gestor.Model.API;
+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.Extrato;
+using Gestor.Model.Domain.Seguros;
+
+namespace Gestor.Application.ViewModels.Comissao;
+
+public class ComissaoViewModel : BaseSegurosViewModel
+{
+ private readonly ServicoExtrato _servico;
+
+ private readonly ApoliceServico _apoliceServico;
+
+ private readonly ParcelaServico _parcelaServico;
+
+ private readonly VendedorServico _vendedorServico;
+
+ private bool _apelido;
+
+ private bool _baixarVisibility;
+
+ private bool _finalizarVisibility;
+
+ private bool _desconsiderarVisibility;
+
+ private bool _desfazerVisibility;
+
+ private ObservableCollection<Seguradora> _seguradoras = new ObservableCollection<Seguradora>();
+
+ private DateTime _inicio = new DateTime(Funcoes.GetNetworkTime().Date.Year, Funcoes.GetNetworkTime().Date.Month, 1);
+
+ private DateTime _fim = Funcoes.GetNetworkTime().Date;
+
+ private bool _baixarPendentes = true;
+
+ private ObservableCollection<Extrato> _extratos = new ObservableCollection<Extrato>();
+
+ private ObservableCollection<Extrato> _extratosFiltrados = new ObservableCollection<Extrato>();
+
+ private Extrato _selectedExtrato;
+
+ private ObservableCollection<Usuario> _usuarios = new ObservableCollection<Usuario>();
+
+ private Usuario _selectedUsuario;
+
+ private List<StatusExtrato> _statusExtrato = new List<StatusExtrato>
+ {
+ (StatusExtrato)1,
+ (StatusExtrato)2,
+ (StatusExtrato)3,
+ (StatusExtrato)4
+ };
+
+ private StatusExtrato _selectedStatusExtrato = (StatusExtrato)1;
+
+ private Seguradora _selectedSeguradora;
+
+ private DetalheExtrato _selectedDetalhe;
+
+ private FiltroStatusDocumento _selectedStatus;
+
+ private Cliente _selectedCliente;
+
+ private string _documentoPrincipal = "";
+
+ private ObservableCollection<DetalheExtrato> _detalheExtrato;
+
+ private bool _allSelected;
+
+ private ObservableCollection<DetalheExtrato> _detalheExtratoFiltrados;
+
+ private int _quantidade;
+
+ private decimal _totalBaixado;
+
+ private decimal _totalPendente;
+
+ private Visibility _isVisibleCliente = (Visibility)2;
+
+ private Visibility _isVisibleApolice = (Visibility)2;
+
+ private Visibility _isVisibleMensagem = (Visibility)2;
+
+ private Visibility _isVisibleDetalhes = (Visibility)2;
+
+ private Visibility _isVisibleExtrato = (Visibility)2;
+
+ private bool _isExpanded = true;
+
+ private ObservableCollection<Documento> _apolices = new ObservableCollection<Documento>();
+
+ private bool _idFatura;
+
+ private Documento _selectedDocumento = new Documento();
+
+ private Parcela _selectedParcela = new Parcela();
+
+ private ObservableCollection<Parcela> _parcelas = new ObservableCollection<Parcela>();
+
+ private decimal _porcentagemExtrato;
+
+ private decimal _porcentagem;
+
+ private decimal _indiceTotal;
+
+ private decimal _indice;
+
+ private decimal _totaExtratosl;
+
+ private decimal _total;
+
+ private bool _criticando;
+
+ private string _filtro = "";
+
+ private string _pesquisaPagamento = "";
+
+ private string _filtroApolice = "";
+
+ private ObservableCollection<string> _filtroPersonalizado = new ObservableCollection<string>();
+
+ public bool Apelido
+ {
+ get
+ {
+ return _apelido;
+ }
+ set
+ {
+ _apelido = value;
+ OnPropertyChanged("Apelido");
+ }
+ }
+
+ public bool BaixarVisibility
+ {
+ get
+ {
+ return _baixarVisibility;
+ }
+ set
+ {
+ _baixarVisibility = value;
+ OnPropertyChanged("BaixarVisibility");
+ }
+ }
+
+ public bool FinalizarVisibility
+ {
+ get
+ {
+ return _finalizarVisibility;
+ }
+ set
+ {
+ _finalizarVisibility = value;
+ OnPropertyChanged("FinalizarVisibility");
+ }
+ }
+
+ public bool DesconsiderarVisibility
+ {
+ get
+ {
+ return _desconsiderarVisibility;
+ }
+ set
+ {
+ _desconsiderarVisibility = value;
+ OnPropertyChanged("DesconsiderarVisibility");
+ }
+ }
+
+ public bool DesfazerVisibility
+ {
+ get
+ {
+ return _desfazerVisibility;
+ }
+ set
+ {
+ _desfazerVisibility = value;
+ OnPropertyChanged("DesfazerVisibility");
+ }
+ }
+
+ public ObservableCollection<Seguradora> Seguradoras
+ {
+ get
+ {
+ return _seguradoras;
+ }
+ set
+ {
+ _seguradoras = value;
+ SelectedSeguradora = SelectedSeguradora ?? value.FirstOrDefault();
+ OnPropertyChanged("Seguradoras");
+ }
+ }
+
+ public DateTime Inicio
+ {
+ get
+ {
+ return _inicio;
+ }
+ set
+ {
+ _inicio = value;
+ OnPropertyChanged("Inicio");
+ }
+ }
+
+ public DateTime Fim
+ {
+ get
+ {
+ return _fim;
+ }
+ set
+ {
+ _fim = value;
+ OnPropertyChanged("Fim");
+ }
+ }
+
+ public bool BaixarPendentes
+ {
+ get
+ {
+ return _baixarPendentes;
+ }
+ set
+ {
+ _baixarPendentes = value;
+ OnPropertyChanged("BaixarPendentes");
+ }
+ }
+
+ public ObservableCollection<Extrato> Extratos
+ {
+ get
+ {
+ return _extratos;
+ }
+ set
+ {
+ _extratos = value;
+ if (value == null || value.Count == 0)
+ {
+ DetalheExtrato = null;
+ DetalheExtratoFiltrados = null;
+ }
+ OnPropertyChanged("Extratos");
+ }
+ }
+
+ public ObservableCollection<Extrato> ExtratosFiltrados
+ {
+ get
+ {
+ return _extratosFiltrados;
+ }
+ set
+ {
+ _extratosFiltrados = value;
+ BaixarPendentes = value != null && value.Count > 0;
+ int enableButtons;
+ if (value != null && value.Count > 0)
+ {
+ Usuario usuario = Recursos.Usuario;
+ enableButtons = ((usuario != null && ((DomainBase)usuario).Id > 0) ? 1 : 0);
+ }
+ else
+ {
+ enableButtons = 0;
+ }
+ base.EnableButtons = (byte)enableButtons != 0;
+ IsVisibleExtrato = (Visibility)((value == null || value.Count <= 0) ? 2 : 0);
+ OnPropertyChanged("ExtratosFiltrados");
+ }
+ }
+
+ public Extrato SelectedExtrato
+ {
+ get
+ {
+ return _selectedExtrato;
+ }
+ set
+ {
+ _selectedExtrato = value;
+ IsVisibleExtrato = (Visibility)((value == null) ? 2 : 0);
+ OnPropertyChanged("SelectedExtrato");
+ }
+ }
+
+ public ObservableCollection<Usuario> Usuarios
+ {
+ get
+ {
+ return _usuarios;
+ }
+ set
+ {
+ _usuarios = value;
+ SelectedUsuario = SelectedUsuario ?? value.FirstOrDefault();
+ OnPropertyChanged("Usuarios");
+ }
+ }
+
+ public Usuario SelectedUsuario
+ {
+ get
+ {
+ return _selectedUsuario;
+ }
+ set
+ {
+ //IL_000f: Unknown result type (might be due to invalid IL or missing references)
+ _selectedUsuario = value;
+ SelecionaSeguradora(SelectedSeguradora, SelectedStatusExtrato);
+ OnPropertyChanged("SelectedUsuario");
+ }
+ }
+
+ public List<StatusExtrato> Status
+ {
+ get
+ {
+ return _statusExtrato;
+ }
+ set
+ {
+ _statusExtrato = value;
+ OnPropertyChanged("Status");
+ }
+ }
+
+ public StatusExtrato SelectedStatusExtrato
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _selectedStatusExtrato;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000e: Unknown result type (might be due to invalid IL or missing references)
+ _selectedStatusExtrato = value;
+ SelecionaSeguradora(SelectedSeguradora, value);
+ OnPropertyChanged("SelectedStatusExtrato");
+ }
+ }
+
+ public Seguradora SelectedSeguradora
+ {
+ get
+ {
+ return _selectedSeguradora;
+ }
+ set
+ {
+ //IL_0015: Unknown result type (might be due to invalid IL or missing references)
+ _selectedSeguradora = value;
+ FiltroPersonalizado = new ObservableCollection<string>();
+ SelecionaSeguradora(value, SelectedStatusExtrato);
+ OnPropertyChanged("SelectedSeguradora");
+ }
+ }
+
+ public DetalheExtrato SelectedDetalhe
+ {
+ get
+ {
+ return _selectedDetalhe;
+ }
+ set
+ {
+ _selectedDetalhe = value;
+ OnPropertyChanged("SelectedDetalhe");
+ }
+ }
+
+ public FiltroStatusDocumento SelectedStatus
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _selectedStatus;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _selectedStatus = value;
+ WorkOnSelectedStatus();
+ OnPropertyChanged("SelectedStatus");
+ }
+ }
+
+ public Cliente SelectedCliente
+ {
+ get
+ {
+ return _selectedCliente;
+ }
+ set
+ {
+ WorkOnSelectedCliente(value);
+ _selectedCliente = value;
+ OnPropertyChanged("SelectedCliente");
+ }
+ }
+
+ public string DocumentoPrincipal
+ {
+ get
+ {
+ return _documentoPrincipal;
+ }
+ set
+ {
+ _documentoPrincipal = value;
+ OnPropertyChanged("DocumentoPrincipal");
+ }
+ }
+
+ public ObservableCollection<DetalheExtrato> DetalheExtrato
+ {
+ get
+ {
+ return _detalheExtrato;
+ }
+ set
+ {
+ _detalheExtrato = value;
+ Quantidade = value?.Count ?? 0;
+ List<StatusParcela> status = new List<StatusParcela>
+ {
+ (StatusParcela)1,
+ (StatusParcela)10,
+ (StatusParcela)13
+ };
+ TotalBaixado = value?.Where((DetalheExtrato x) => x.Status.HasValue && x.ValorComissao.HasValue && status.Contains(x.Status.Value)).Sum((DetalheExtrato x) => x.ValorComissao.Value) ?? 0m;
+ Extrato selectedExtrato = SelectedExtrato;
+ TotalPendente = ((selectedExtrato != null && selectedExtrato.Bruto.HasValue) ? (SelectedExtrato.Bruto.Value - TotalBaixado) : 0m);
+ OnPropertyChanged("DetalheExtrato");
+ }
+ }
+
+ public bool AllSelected
+ {
+ get
+ {
+ return _allSelected;
+ }
+ set
+ {
+ _allSelected = value;
+ OnPropertyChanged("AllSelected");
+ if (!_carregadoDetalhes)
+ {
+ Selecionar(value);
+ }
+ }
+ }
+
+ public ObservableCollection<DetalheExtrato> DetalheExtratoFiltrados
+ {
+ get
+ {
+ return _detalheExtratoFiltrados;
+ }
+ set
+ {
+ _detalheExtratoFiltrados = value;
+ OnPropertyChanged("DetalheExtratoFiltrados");
+ }
+ }
+
+ public int Quantidade
+ {
+ get
+ {
+ return _quantidade;
+ }
+ set
+ {
+ _quantidade = value;
+ OnPropertyChanged("Quantidade");
+ }
+ }
+
+ public decimal TotalBaixado
+ {
+ get
+ {
+ return _totalBaixado;
+ }
+ set
+ {
+ _totalBaixado = value;
+ OnPropertyChanged("TotalBaixado");
+ }
+ }
+
+ public decimal TotalPendente
+ {
+ get
+ {
+ return _totalPendente;
+ }
+ set
+ {
+ _totalPendente = value;
+ OnPropertyChanged("TotalPendente");
+ }
+ }
+
+ public Visibility IsVisibleCliente
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisibleCliente;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisibleCliente = value;
+ OnPropertyChanged("IsVisibleCliente");
+ }
+ }
+
+ public Visibility IsVisibleApolice
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisibleApolice;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisibleApolice = value;
+ OnPropertyChanged("IsVisibleApolice");
+ }
+ }
+
+ public Visibility IsVisibleMensagem
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisibleMensagem;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisibleMensagem = value;
+ OnPropertyChanged("IsVisibleMensagem");
+ }
+ }
+
+ public Visibility IsVisibleDetalhes
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisibleDetalhes;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisibleDetalhes = value;
+ OnPropertyChanged("IsVisibleDetalhes");
+ }
+ }
+
+ public Visibility IsVisibleExtrato
+ {
+ get
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ return _isVisibleExtrato;
+ }
+ set
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0002: Unknown result type (might be due to invalid IL or missing references)
+ _isVisibleExtrato = value;
+ OnPropertyChanged("IsVisibleExtrato");
+ }
+ }
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return _isExpanded;
+ }
+ set
+ {
+ _isExpanded = value;
+ OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ private bool _carregadoDetalhes { get; set; }
+
+ public ObservableCollection<Documento> Apolices
+ {
+ get
+ {
+ return _apolices;
+ }
+ set
+ {
+ _apolices = value;
+ OnPropertyChanged("Apolices");
+ }
+ }
+
+ public ObservableCollection<Documento> TodasApolices { get; set; }
+
+ public bool IsFatura
+ {
+ get
+ {
+ return _idFatura;
+ }
+ set
+ {
+ _idFatura = value;
+ OnPropertyChanged("IsFatura");
+ }
+ }
+
+ public Documento SelectedDocumento
+ {
+ get
+ {
+ return _selectedDocumento;
+ }
+ set
+ {
+ _selectedDocumento = value;
+ WorkOnSelectedDocumento(value);
+ OnPropertyChanged("SelectedDocumento");
+ }
+ }
+
+ public Parcela SelectedParcela
+ {
+ get
+ {
+ return _selectedParcela;
+ }
+ set
+ {
+ _selectedParcela = value;
+ OnPropertyChanged("SelectedParcela");
+ }
+ }
+
+ public ObservableCollection<Parcela> Parcelas
+ {
+ get
+ {
+ return _parcelas;
+ }
+ set
+ {
+ _parcelas = value;
+ OnPropertyChanged("Parcelas");
+ }
+ }
+
+ public decimal PorcentagemExtrato
+ {
+ get
+ {
+ return _porcentagemExtrato;
+ }
+ set
+ {
+ _porcentagemExtrato = value;
+ OnPropertyChanged("PorcentagemExtrato");
+ }
+ }
+
+ public decimal Porcentagem
+ {
+ get
+ {
+ return _porcentagem;
+ }
+ set
+ {
+ _porcentagem = value;
+ OnPropertyChanged("Porcentagem");
+ }
+ }
+
+ public decimal IndiceTotal
+ {
+ get
+ {
+ return _indiceTotal;
+ }
+ set
+ {
+ _indiceTotal = value;
+ OnPropertyChanged("IndiceTotal");
+ }
+ }
+
+ public decimal Indice
+ {
+ get
+ {
+ return _indice;
+ }
+ set
+ {
+ _indice = value;
+ OnPropertyChanged("Indice");
+ }
+ }
+
+ public decimal TotalExtratos
+ {
+ get
+ {
+ return _totaExtratosl;
+ }
+ set
+ {
+ _totaExtratosl = value;
+ OnPropertyChanged("TotalExtratos");
+ }
+ }
+
+ public decimal Total
+ {
+ get
+ {
+ return _total;
+ }
+ set
+ {
+ _total = value;
+ OnPropertyChanged("Total");
+ }
+ }
+
+ public bool Buscando { get; set; }
+
+ public bool Criticando
+ {
+ get
+ {
+ return _criticando;
+ }
+ set
+ {
+ _criticando = value;
+ OnPropertyChanged("Criticando");
+ }
+ }
+
+ private List<Imposto> Impostos { get; set; } = new List<Imposto>();
+
+
+ private bool Carregando { get; set; }
+
+ public string Filtro
+ {
+ get
+ {
+ return _filtro;
+ }
+ set
+ {
+ _filtro = value;
+ OnPropertyChanged("Filtro");
+ }
+ }
+
+ public string PesquisaPagamento
+ {
+ get
+ {
+ return _pesquisaPagamento;
+ }
+ set
+ {
+ _pesquisaPagamento = value;
+ OnPropertyChanged("PesquisaPagamento");
+ }
+ }
+
+ public string FiltroApolice
+ {
+ get
+ {
+ return _filtroApolice;
+ }
+ set
+ {
+ _filtroApolice = value;
+ OnPropertyChanged("FiltroApolice");
+ }
+ }
+
+ public ObservableCollection<string> FiltroPersonalizado
+ {
+ get
+ {
+ return _filtroPersonalizado;
+ }
+ set
+ {
+ _filtroPersonalizado = value;
+ OnPropertyChanged("FiltroPersonalizado");
+ }
+ }
+
+ public ComissaoViewModel()
+ {
+ //IL_00a5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b7: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00cc: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00f5: Expected O, but got Unknown
+ //IL_00f6: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0100: Expected O, but got Unknown
+ _servico = new ServicoExtrato();
+ _apoliceServico = new ApoliceServico();
+ _parcelaServico = new ParcelaServico();
+ _vendedorServico = new VendedorServico();
+ Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 6);
+ SelecionaSeguradoras();
+ base.EnableMenu = true;
+ }
+
+ public void SelecionaSeguradoras()
+ {
+ //IL_005c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0061: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0069: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0074: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0084: Expected O, but got Unknown
+ //IL_00fd: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0102: Unknown result type (might be due to invalid IL or missing references)
+ //IL_010a: Unknown result type (might be due to invalid IL or missing references)
+ //IL_011a: Expected O, but got Unknown
+ Loading(isLoading: true);
+ List<Seguradora> list = (from x in Recursos.Seguradoras
+ where x.Ativo
+ orderby x.Nome
+ select x).ToList();
+ list.Insert(0, new Seguradora
+ {
+ Id = 0L,
+ Nome = "TODAS AS SEGURADORAS",
+ NomeSocial = "TODAS DAS SEGURADORAS"
+ });
+ List<Usuario> list2 = (from x in Recursos.Usuarios
+ where !x.Excluido
+ orderby x.IdEmpresa, x.Nome
+ select x).ToList();
+ list2.Insert(0, new Usuario
+ {
+ Id = 0L,
+ Nome = "TODOS OS USUÁRIOS"
+ });
+ Usuarios = new ObservableCollection<Usuario>(list2);
+ Seguradoras = new ObservableCollection<Seguradora>(list);
+ Loading(isLoading: false);
+ }
+
+ public async void SelecionaSeguradora(Seguradora value, StatusExtrato status, Extrato extrato = null)
+ {
+ //IL_001e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_001f: Unknown result type (might be due to invalid IL or missing references)
+ if (Carregando)
+ {
+ return;
+ }
+ if (Inicio > Fim)
+ {
+ await ShowMessage("DATA DE INÍCIO NÃO PODE SER MAR QUE A DATA FINAL");
+ return;
+ }
+ Filtro = string.Empty;
+ FiltroApolice = string.Empty;
+ if (value == null)
+ {
+ Extratos = null;
+ ExtratosFiltrados = null;
+ DetalheExtrato = null;
+ DetalheExtratoFiltrados = null;
+ SelectedExtrato = null;
+ SelectedDetalhe = null;
+ return;
+ }
+ Loading(isLoading: true);
+ IsVisibleExtrato = (Visibility)2;
+ BaixarPendentes = (int)status == 1;
+ DetalheExtrato = null;
+ StatusExtrato status2 = (StatusExtrato)(((int)status == 2) ? 3 : ((int)status));
+ List<Extrato> list = await _servico.BuscarExtrato(((DomainBase)value).Id, ((DomainBase)SelectedUsuario).Id, status2, Inicio, Fim);
+ Extratos = (((int)status == 2) ? new ObservableCollection<Extrato>(list.Where((Extrato x) => !x.Completo)) : (((int)status == 3) ? new ObservableCollection<Extrato>(list.Where((Extrato x) => x.Completo)) : new ObservableCollection<Extrato>(list)));
+ ExtratosFiltrados = Extratos;
+ if (FiltroPersonalizado.Count > 0)
+ {
+ FiltrarExtrato();
+ }
+ ComissaoViewModel comissaoViewModel = this;
+ ObservableCollection<Extrato> extratosFiltrados = ExtratosFiltrados;
+ comissaoViewModel.IsExpanded = extratosFiltrados != null && extratosFiltrados.Count > 0;
+ Extrato extrato2 = ((extrato == null) ? ExtratosFiltrados.FirstOrDefault() : ((IEnumerable<Extrato>)ExtratosFiltrados).FirstOrDefault((Func<Extrato, bool>)((Extrato x) => ((DomainBase)x).Id == ((DomainBase)extrato).Id)));
+ await SelecionaExtrato(extrato2);
+ Loading(isLoading: false);
+ if (SelectedSeguradora != null)
+ {
+ RegistrarAcao($"CONSULTOU COMISSÃO AUTOMÁTICA NO PERÍODO ENTRE {Inicio:d} E {Fim:d}", 0L, (TipoTela)35, string.Format("USUÁRIO IMPORTAÇÃO: {0} ({1})\nSEGURADORA: {2} ({3})\nSTATUS: {4}\nPESQUISA PERSONALIZADA: \"{5}\"", SelectedUsuario.Nome, ((DomainBase)SelectedUsuario).Id, SelectedSeguradora.Nome, ((DomainBase)SelectedSeguradora).Id, ValidationHelper.GetDescription((Enum)(object)SelectedStatusExtrato), ValidationHelper.Join((IEnumerable<string>)FiltroPersonalizado, ", ")));
+ }
+ }
+
+ public async void WorkOnSelectedStatus()
+ {
+ if (SelectedCliente != null && !Buscando)
+ {
+ await SelecionaCliente(SelectedCliente);
+ }
+ }
+
+ private async void WorkOnSelectedCliente(Cliente value)
+ {
+ if (value == null || ((DomainBase)value).Id == 0L)
+ {
+ IsVisibleCliente = (Visibility)2;
+ IsVisibleApolice = (Visibility)2;
+ IsVisibleMensagem = (Visibility)2;
+ DocumentoPrincipal = string.Empty;
+ SelectedDocumento = null;
+ SelectedParcela = null;
+ return;
+ }
+ IsVisibleCliente = (Visibility)0;
+ if (!Buscando)
+ {
+ Loading(isLoading: true);
+ IsVisibleDetalhes = (Visibility)2;
+ }
+ if (!Buscando)
+ {
+ Buscando = true;
+ await SelecionaCliente(value);
+ await SelecionaDocumento(Apolices.FirstOrDefault());
+ Buscando = false;
+ value.DocumentoPrincipal = value.DocumentoPrincipal.GetValueOrDefault();
+ switch (value.DocumentoPrincipal)
+ {
+ case 0L:
+ DocumentoPrincipal = value.Documento ?? "";
+ break;
+ case 1L:
+ DocumentoPrincipal = value.Rne ?? "";
+ break;
+ case 2L:
+ DocumentoPrincipal = value.Cei ?? "";
+ break;
+ }
+ IsVisibleDetalhes = (Visibility)0;
+ Loading(isLoading: false);
+ }
+ }
+
+ private void WorkOnSelectedDocumento(Documento value)
+ {
+ //IL_001e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0024: Invalid comparison between Unknown and I4
+ if (value != null && ((DomainBase)value).Id != 0L && !Buscando)
+ {
+ IsFatura = (int)value.TipoRecebimento.GetValueOrDefault() == 2;
+ }
+ }
+
+ private void Selecionar(bool value)
+ {
+ ExtensionMethods.ForEach<DetalheExtrato>((IEnumerable<DetalheExtrato>)DetalheExtratoFiltrados, (Action<DetalheExtrato>)delegate(DetalheExtrato x)
+ {
+ x.Selecionado = value;
+ });
+ }
+
+ public async Task SelecionaExtrato(Extrato extrato)
+ {
+ if (extrato != null && ((DomainBase)extrato).Id != 0L)
+ {
+ Loading(isLoading: true);
+ IsVisibleDetalhes = (Visibility)2;
+ SelectedExtrato = extrato;
+ PesquisaPagamento = string.Empty;
+ await CarregaDetalhes(extrato);
+ IsVisibleDetalhes = (Visibility)0;
+ Loading(isLoading: false);
+ }
+ }
+
+ private void SelecionaNormal()
+ {
+ ExtensionMethods.ForEach<DetalheExtrato>((IEnumerable<DetalheExtrato>)DetalheExtrato, (Action<DetalheExtrato>)delegate(DetalheExtrato detalhe)
+ {
+ //IL_000a: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0010: Invalid comparison between Unknown and I4
+ detalhe.IsNormal = (int)detalhe.SubTipo.GetValueOrDefault() == 1;
+ });
+ }
+
+ public async Task CarregaDetalhes(Extrato extrato)
+ {
+ if (extrato == null || ((DomainBase)extrato).Id == 0L)
+ {
+ return;
+ }
+ _carregadoDetalhes = true;
+ AllSelected = false;
+ DetalheExtrato = await _servico.BuscarDetalhes(((DomainBase)extrato).Id);
+ DetalheExtratoFiltrados = DetalheExtrato;
+ SelecionaNormal();
+ _carregadoDetalhes = false;
+ List<StatusParcela> statusDesconsiderar = new List<StatusParcela>
+ {
+ (StatusParcela)2,
+ (StatusParcela)3
+ };
+ List<StatusParcela> statusDesfazer = new List<StatusParcela>
+ {
+ (StatusParcela)1,
+ (StatusParcela)13,
+ (StatusParcela)10
+ };
+ List<StatusParcela> statusBaixar = new List<StatusParcela>
+ {
+ (StatusParcela)16,
+ (StatusParcela)9,
+ (StatusParcela)14,
+ (StatusParcela)4,
+ (StatusParcela)17,
+ (StatusParcela)18
+ };
+ List<StatusParcela> statusFinalizar = new List<StatusParcela>
+ {
+ (StatusParcela)1,
+ (StatusParcela)13,
+ (StatusParcela)10,
+ (StatusParcela)5,
+ (StatusParcela)12,
+ (StatusParcela)6,
+ (StatusParcela)8
+ };
+ DesfazerVisibility = DetalheExtrato.Any((DetalheExtrato x) => x.Status.HasValue && statusDesfazer.Contains(x.Status.Value));
+ DesconsiderarVisibility = DetalheExtrato.Any((DetalheExtrato x) => x.Status.HasValue && statusDesconsiderar.Contains(x.Status.Value));
+ BaixarVisibility = DetalheExtrato.Any((DetalheExtrato x) => x.Status.HasValue && statusBaixar.Contains(x.Status.Value));
+ if (SelectedExtrato != null)
+ {
+ FinalizarVisibility = DetalheExtrato.All((DetalheExtrato x) => x.Status.HasValue && statusFinalizar.Contains(x.Status.Value) && ((int)SelectedExtrato.Status == 1 || !SelectedExtrato.Completo));
+ }
+ }
+
+ private async Task<ObservableCollection<DetalheExtrato>> CarregarDetalhes(Extrato extrato)
+ {
+ return await _servico.BuscarDetalhes(((DomainBase)extrato).Id);
+ }
+
+ internal async Task<List<DetalheExtrato>> FiltrarDetalhe(string value)
+ {
+ return await Task.Run(() => FiltrarDetalheExtrato(value));
+ }
+
+ public List<DetalheExtrato> FiltrarDetalheExtrato(string filter)
+ {
+ if (DetalheExtrato == null)
+ {
+ return null;
+ }
+ DetalheExtratoFiltrados = (string.IsNullOrWhiteSpace(filter) ? DetalheExtrato : new ObservableCollection<DetalheExtrato>(from x in DetalheExtrato
+ where ValidationHelper.RemoveDiacritics(x.Cliente).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) || x.Apolice.Contains(filter) || x.Endosso.Contains(filter)
+ orderby x.Cliente
+ select x));
+ return DetalheExtratoFiltrados.ToList();
+ }
+
+ public List<DetalheExtrato> FiltrarDetalheExtrato(long id)
+ {
+ DetalheExtratoFiltrados = new ObservableCollection<DetalheExtrato>(DetalheExtrato.Where((DetalheExtrato x) => ((DomainBase)x).Id == id));
+ return DetalheExtratoFiltrados.ToList();
+ }
+
+ public async Task BuscarCriticado(DetalheExtrato detalhe)
+ {
+ if (detalhe == null)
+ {
+ return;
+ }
+ SelectedDetalhe = DetalheExtratoFiltrados.First((DetalheExtrato x) => ((DomainBase)x).Id == ((DomainBase)detalhe).Id);
+ if (!SelectedDetalhe.Parcela.HasValue && !SelectedDetalhe.Documento.HasValue)
+ {
+ TodasApolices = null;
+ Apolices = null;
+ Parcelas = null;
+ return;
+ }
+ Buscando = true;
+ ParcelaServico parcelaServico = new ParcelaServico();
+ Parcela parcela = null;
+ Documento documento = null;
+ if (SelectedDetalhe.Parcela.HasValue)
+ {
+ parcela = await parcelaServico.BuscarParcela(SelectedDetalhe.Parcela.Value);
+ if (parcela != null)
+ {
+ detalhe.Documento = ((DomainBase)parcela.Documento).Id;
+ documento = parcela.Documento;
+ }
+ }
+ if (SelectedDetalhe.Documento.HasValue && !SelectedDetalhe.Parcela.HasValue)
+ {
+ documento = await _apoliceServico.BuscarApoliceAsync(SelectedDetalhe.Documento.Value);
+ }
+ if (documento == null)
+ {
+ Buscando = false;
+ return;
+ }
+ SelectedCliente = documento.Controle.Cliente;
+ await SelecionaCliente(documento.Controle.Cliente);
+ SelectedDocumento = ((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == ((DomainBase)documento).Id));
+ await SelecionaDocumento(documento);
+ SelecionaParcela(parcela);
+ Buscando = false;
+ }
+
+ public async Task SelecionaCliente(Cliente value)
+ {
+ if (value == null || ((DomainBase)value).Id == 0L)
+ {
+ return;
+ }
+ ObservableCollection<Documento> source = await _apoliceServico.BuscarApolicesComissao(((DomainBase)value).Id, SelectedStatus);
+ FiltroApolice = string.Empty;
+ long id = ((DomainBase)SelectedExtrato.Seguradora).Id;
+ List<long> seguradoras;
+ if (id <= 544)
+ {
+ if (id <= 310)
+ {
+ if (id > 182)
+ {
+ if (id <= 261)
+ {
+ if (id == 216)
+ {
+ goto IL_06db;
+ }
+ if ((ulong)(id - 258) <= 3uL)
+ {
+ goto IL_0858;
+ }
+ }
+ else
+ {
+ if ((ulong)(id - 291) <= 1uL || id == 296)
+ {
+ goto IL_0534;
+ }
+ if (id == 310)
+ {
+ goto IL_0792;
+ }
+ }
+ goto IL_03ef;
+ }
+ if (id <= 93)
+ {
+ if (id == 28)
+ {
+ goto IL_041a;
+ }
+ if ((ulong)(id - 89) > 4uL)
+ {
+ goto IL_03ef;
+ }
+ seguradoras = new List<long> { 89L, 90L, 91L, 92L, 93L };
+ }
+ else
+ {
+ if ((ulong)(id - 112) > 1uL)
+ {
+ if (id != 182)
+ {
+ goto IL_03ef;
+ }
+ goto IL_08e2;
+ }
+ seguradoras = new List<long> { 112L, 113L };
+ }
+ }
+ else
+ {
+ if (id <= 400)
+ {
+ if (id <= 331)
+ {
+ if (id == 328)
+ {
+ goto IL_04aa;
+ }
+ if (id == 331)
+ {
+ goto IL_04e3;
+ }
+ }
+ else
+ {
+ if (id == 341)
+ {
+ goto IL_07d7;
+ }
+ if (id == 374)
+ {
+ goto IL_0804;
+ }
+ if (id == 400)
+ {
+ goto IL_0534;
+ }
+ }
+ goto IL_03ef;
+ }
+ if (id <= 480)
+ {
+ if (id == 402)
+ {
+ goto IL_0534;
+ }
+ if (id != 480)
+ {
+ goto IL_03ef;
+ }
+ seguradoras = new List<long>
+ {
+ 475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L, 484L,
+ 485L, 486L, 487L, 558L, 580L, 664L
+ };
+ }
+ else
+ {
+ if (id != 501)
+ {
+ if (id == 543)
+ {
+ goto IL_04e3;
+ }
+ if (id != 544)
+ {
+ goto IL_03ef;
+ }
+ goto IL_0759;
+ }
+ seguradoras = new List<long> { 498L, 499L, 500L, 501L, 502L };
+ }
+ }
+ goto IL_090a;
+ }
+ if (id <= 630)
+ {
+ if (id <= 562)
+ {
+ if (id <= 552)
+ {
+ if (id == 548 || id == 552)
+ {
+ goto IL_0759;
+ }
+ }
+ else
+ {
+ if ((ulong)(id - 554) <= 1uL)
+ {
+ goto IL_0534;
+ }
+ if (id == 560)
+ {
+ goto IL_06db;
+ }
+ if (id == 562)
+ {
+ goto IL_04e3;
+ }
+ }
+ }
+ else if (id <= 574)
+ {
+ if (id == 570)
+ {
+ goto IL_0858;
+ }
+ if (id == 574)
+ {
+ goto IL_0534;
+ }
+ }
+ else
+ {
+ if (id == 578)
+ {
+ goto IL_0804;
+ }
+ long num = id - 591;
+ if ((ulong)num <= 7uL)
+ {
+ switch (num)
+ {
+ case 2L:
+ case 5L:
+ case 6L:
+ goto IL_03ef;
+ case 0L:
+ case 1L:
+ case 3L:
+ goto IL_041a;
+ case 4L:
+ goto IL_04e3;
+ case 7L:
+ goto IL_0858;
+ }
+ }
+ if (id == 630)
+ {
+ goto IL_0792;
+ }
+ }
+ }
+ else
+ {
+ if (id > 674)
+ {
+ if (id <= 711)
+ {
+ if (id != 694)
+ {
+ if (id != 711)
+ {
+ goto IL_03ef;
+ }
+ goto IL_04aa;
+ }
+ }
+ else if (id != 884)
+ {
+ if (id == 982)
+ {
+ goto IL_04e3;
+ }
+ if (id != 1006)
+ {
+ goto IL_03ef;
+ }
+ goto IL_08e2;
+ }
+ goto IL_0534;
+ }
+ if (id <= 643)
+ {
+ if (id == 631)
+ {
+ goto IL_07d7;
+ }
+ long num2 = id - 639;
+ if ((ulong)num2 <= 4uL)
+ {
+ switch (num2)
+ {
+ case 2L:
+ case 4L:
+ goto IL_0534;
+ case 0L:
+ goto IL_0792;
+ }
+ }
+ }
+ else
+ {
+ if (id == 649)
+ {
+ goto IL_041a;
+ }
+ if (id == 650)
+ {
+ goto IL_0792;
+ }
+ if (id == 674)
+ {
+ goto IL_0534;
+ }
+ }
+ }
+ goto IL_03ef;
+ IL_06db:
+ seguradoras = new List<long> { 560L, 216L };
+ goto IL_090a;
+ IL_0534:
+ seguradoras = new List<long>
+ {
+ 70L, 291L, 292L, 296L, 400L, 401L, 402L, 554L, 555L, 574L,
+ 641L, 643L, 674L, 694L, 884L, 348L
+ };
+ goto IL_090a;
+ IL_04aa:
+ seguradoras = new List<long> { 328L, 329L, 711L };
+ goto IL_090a;
+ IL_0759:
+ seguradoras = new List<long> { 544L, 548L, 552L };
+ goto IL_090a;
+ IL_0858:
+ seguradoras = new List<long> { 258L, 259L, 260L, 261L, 570L, 598L, 472L, 595L, 741L, 982L };
+ goto IL_090a;
+ IL_0804:
+ seguradoras = new List<long> { 374L, 578L };
+ goto IL_090a;
+ IL_03ef:
+ seguradoras = new List<long> { ((DomainBase)SelectedExtrato.Seguradora).Id };
+ goto IL_090a;
+ IL_090a:
+ TodasApolices = new ObservableCollection<Documento>(from x in source
+ where x.Controle.Seguradora != null && seguradoras.Contains(((DomainBase)x.Controle.Seguradora).Id)
+ orderby x.Vigencia2, ((DomainBase)x.Controle).Id
+ select x);
+ Apolices = TodasApolices;
+ IsVisibleApolice = (Visibility)((TodasApolices.Count <= 0) ? 2 : 0);
+ IsVisibleMensagem = (Visibility)((TodasApolices.Count > 0) ? 2 : 0);
+ return;
+ IL_041a:
+ seguradoras = new List<long> { 28L, 591L, 592L, 594L, 649L };
+ goto IL_090a;
+ IL_04e3:
+ seguradoras = new List<long> { 331L, 543L, 562L, 595L, 982L };
+ goto IL_090a;
+ IL_07d7:
+ seguradoras = new List<long> { 341L, 631L };
+ goto IL_090a;
+ IL_0792:
+ seguradoras = new List<long> { 310L, 630L, 639L, 650L };
+ goto IL_090a;
+ IL_08e2:
+ seguradoras = new List<long> { 182L, 1006L };
+ goto IL_090a;
+ }
+
+ public async Task SelecionaDocumento(Documento value)
+ {
+ if (value != null && ((DomainBase)value).Id != 0L)
+ {
+ SelectedDocumento = ((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == ((DomainBase)value).Id));
+ Parcelas = await _parcelaServico.BuscarParcelasAsync(((DomainBase)value).Id);
+ }
+ }
+
+ public void SelecionaParcela(Parcela value)
+ {
+ if (value != null && ((DomainBase)value).Id != 0L)
+ {
+ SelectedParcela = ((IEnumerable<Parcela>)Parcelas).FirstOrDefault((Func<Parcela, bool>)((Parcela x) => ((DomainBase)x).Id == ((DomainBase)value).Id));
+ }
+ }
+
+ public async Task AtualizarExtrato()
+ {
+ if (DetalheExtratoFiltrados == null || DetalheExtratoFiltrados.Count == 0)
+ {
+ return;
+ }
+ if (DetalheExtratoFiltrados.All((DetalheExtrato x) => !x.Selecionado))
+ {
+ await ShowMessage("NECESSÁRIO SELECIONAR QUAL PARCELA DESEJA ATUALIZAR.");
+ return;
+ }
+ Loading(isLoading: true);
+ IsVisibleDetalhes = (Visibility)2;
+ base.IsVisible = (Visibility)2;
+ await _parcelaServico.UpdateDetalhes(DetalheExtratoFiltrados.Where((DetalheExtrato x) => x.Selecionado).ToList());
+ base.IsVisible = (Visibility)0;
+ IsVisibleDetalhes = (Visibility)0;
+ Loading(isLoading: false);
+ RegistrarAcao($"ATUALIZOU EXTRATO DE ID \n{((DomainBase)SelectedExtrato).Id}\n", ((DomainBase)SelectedExtrato).Id, (TipoTela)35);
+ ToggleSnackBar("EXTRATO ATUALIZADO COM SUCESSO");
+ }
+
+ public async Task Criticar(DetalheExtrato detalhe, bool critica)
+ {
+ if (detalhe == null || (SelectedDocumento == null && critica))
+ {
+ return;
+ }
+ Loading(isLoading: true);
+ IsVisibleDetalhes = (Visibility)2;
+ List<DetalheExtrato> detalhesVinculados = new List<DetalheExtrato>();
+ if (!critica)
+ {
+ detalhe.Status = (StatusParcela)6;
+ detalhe.Documento = null;
+ detalhe.Parcela = null;
+ goto IL_0484;
+ }
+ bool flag = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 12);
+ SubTipo? subTipo = detalhe.SubTipo;
+ if (subTipo.HasValue)
+ {
+ SubTipo valueOrDefault = subTipo.GetValueOrDefault();
+ if ((int)valueOrDefault <= 1)
+ {
+ Parcela ultimaBaixa = ((IEnumerable<Parcela>)Parcelas).FirstOrDefault((Func<Parcela, bool>)((Parcela x) => !x.DataRecebimento.HasValue));
+ detalhe.Status = (StatusParcela)((ultimaBaixa != null && ultimaBaixa.NumeroParcela < SelectedParcela.NumeroParcela) ? 7 : (SelectedParcela.DataRecebimento.HasValue ? 5 : 14));
+ detalhe.Documento = ((DomainBase)SelectedDocumento).Id;
+ detalhe.Parcela = ((DomainBase)SelectedParcela).Id;
+ detalhesVinculados = (from x in DetalheExtrato
+ where x.Cliente == detalhe.Cliente && x.Apolice == detalhe.Apolice && x.NumeroParcela != detalhe.NumeroParcela && (int)x.SubTipo.GetValueOrDefault() == 1 && ((int)x.Status.GetValueOrDefault() == 2 || (int)x.Status.GetValueOrDefault() == 3)
+ orderby x.NumeroParcela
+ select x).ToList();
+ bool flag2 = detalhesVinculados.Count > 0;
+ if (flag2)
+ {
+ flag2 = await ShowMessage("DESEJA CRITICAR AUTOMATICAMENTE AS PRÓXIMAS PARCELAS DESTE DOCUMENTO?", "SIM", "NÃO");
+ }
+ if (flag2)
+ {
+ detalhesVinculados.ForEach(delegate(DetalheExtrato x)
+ {
+ if (int.TryParse(x.NumeroParcela, out var _))
+ {
+ Parcela val = ((IEnumerable<Parcela>)Parcelas).FirstOrDefault((Func<Parcela, bool>)((Parcela p) => p.NumeroParcela == int.Parse(x.NumeroParcela)));
+ if (val != null)
+ {
+ x.Status = (StatusParcela)((ultimaBaixa != null && ultimaBaixa.NumeroParcela < val.NumeroParcela) ? 7 : (val.DataRecebimento.HasValue ? 5 : 14));
+ x.Documento = ((DomainBase)SelectedDocumento).Id;
+ x.Parcela = ((DomainBase)val).Id;
+ }
+ }
+ });
+ }
+ else
+ {
+ detalhesVinculados = null;
+ }
+ goto IL_0484;
+ }
+ }
+ detalhe.Status = (StatusParcela)((SelectedParcela == null || (!flag && (int)SelectedParcela.SubTipo == 1)) ? 17 : (SelectedParcela.DataRecebimento.HasValue ? 5 : 14));
+ detalhe.Documento = ((DomainBase)SelectedDocumento).Id;
+ DetalheExtrato obj = detalhe;
+ if (SelectedParcela == null || ((DomainBase)SelectedParcela).Id == 0L)
+ {
+ goto IL_0225;
+ }
+ if (!flag)
+ {
+ Parcela selectedParcela = SelectedParcela;
+ if (selectedParcela != null && (int)selectedParcela.SubTipo == 1)
+ {
+ goto IL_0225;
+ }
+ }
+ long? parcela = ((DomainBase)SelectedParcela).Id;
+ goto IL_022e;
+ IL_0484:
+ await _servico.Save(detalhe);
+ if (!_servico.Sucesso)
+ {
+ Loading(isLoading: false);
+ return;
+ }
+ if (detalhesVinculados != null && detalhesVinculados.Count > 0)
+ {
+ foreach (DetalheExtrato item in detalhesVinculados)
+ {
+ await _servico.Save(item);
+ if (!_servico.Sucesso)
+ {
+ return;
+ }
+ }
+ }
+ await CarregaDetalhes(SelectedExtrato);
+ IsVisibleDetalhes = (Visibility)0;
+ Loading(isLoading: false);
+ ToggleSnackBar("CRÍTICA REALIZADA COM SUCESSO");
+ string arg = ((SelectedParcela == null) ? "ESPECIAL" : SelectedParcela.NumeroParcela.ToString());
+ RegistrarAcao(string.Format("{0} PARCELA NÚMERO \"{1}\" DO EXTRATO NÚMERO \n{2}\n, ID {3}", critica ? "CRITICOU" : "DESCONSIDEROU", detalhe.NumeroParcela, detalhe.Extrato.Numero, ((DomainBase)detalhe.Extrato).Id), ((DomainBase)SelectedExtrato).Id, (TipoTela)35, critica ? $"CRITICOU A PARCELA \"{arg}\" DO DOCUMENTO DE ID \n{((DomainBase)SelectedDocumento).Id}\n" : "");
+ return;
+ IL_0225:
+ parcela = null;
+ goto IL_022e;
+ IL_022e:
+ obj.Parcela = parcela;
+ goto IL_0484;
+ }
+
+ public async Task BaixarExtrato(bool selecionados = false)
+ {
+ if (DetalheExtrato == null || DetalheExtrato.Count == 0)
+ {
+ return;
+ }
+ if (DetalheExtrato.ToList().All((DetalheExtrato x) => (int)x.Status.GetValueOrDefault() == 6))
+ {
+ SelectedExtrato.Status = (StatusExtrato)3;
+ await _servico.Save(SelectedExtrato);
+ if (_servico.Sucesso)
+ {
+ SelectedStatusExtrato = (StatusExtrato)3;
+ await SelecionaExtrato(SelectedExtrato);
+ ToggleSnackBar("TODAS AS PARCELAS FORAM DESCONSIDERADAS PELO USUARIO");
+ }
+ return;
+ }
+ StatusExtrato extrato = SelectedExtrato.Status;
+ List<DetalheExtrato> extrato2 = (selecionados ? DetalheExtrato.Where((DetalheExtrato x) => x.Selecionado).ToList() : DetalheExtrato.ToList());
+ await BaixarComissao(extrato2, selecionados);
+ RegistrarAcao($"BAIXOU EXTRATO DE ID \n{((DomainBase)SelectedExtrato).Id}\n", ((DomainBase)SelectedExtrato).Id, (TipoTela)35);
+ if ((int)SelectedExtrato.Status != 3)
+ {
+ SelectedStatusExtrato = SelectedExtrato.Status;
+ }
+ SelectedExtrato = null;
+ SelecionaSeguradora(SelectedSeguradora, extrato);
+ ToggleSnackBar("EXTRATO BAIXADO COM SUCESSO");
+ }
+
+ private static VendedorParcela PropriaCorretora()
+ {
+ //IL_002a: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002f: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0036: Unknown result type (might be due to invalid IL or missing references)
+ //IL_004a: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0051: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0065: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0095: Expected O, but got Unknown
+ Vendedor vendedor = ((IEnumerable<Vendedor>)Recursos.Vendedores).FirstOrDefault((Func<Vendedor, bool>)((Vendedor x) => x.IdEmpresa == ((DomainBase)Recursos.Empresa).Id && x.Corretora));
+ return new VendedorParcela
+ {
+ Repasse = null,
+ ValorRepasse = default(decimal),
+ Vendedor = vendedor,
+ PorcentagemRepasse = default(decimal),
+ TipoVendedor = Recursos.TipoVendedor.First((TipoVendedor x) => ((DomainBase)x).Id == 1)
+ };
+ }
+
+ private async Task BaixarComissao(List<DetalheExtrato> extrato, bool selecionados = false)
+ {
+ _ = 3;
+ try
+ {
+ List<StatusParcela> status = new List<StatusParcela>
+ {
+ (StatusParcela)9,
+ (StatusParcela)14,
+ (StatusParcela)16,
+ (StatusParcela)4,
+ (StatusParcela)17,
+ (StatusParcela)15,
+ (StatusParcela)7,
+ (StatusParcela)18
+ };
+ List<StatusParcela> statusAproximacao = new List<StatusParcela>
+ {
+ (StatusParcela)16,
+ (StatusParcela)18
+ };
+ bool flag = !selecionados && DetalheExtrato.ToList().Any((DetalheExtrato x) => statusAproximacao.Contains(x.Status.Value));
+ if (flag)
+ {
+ flag = !(await ShowMessage("O EXTRATO CONTÉM PARCELAS ENCONTRADAS POR APROXIMAÇÃO, DESEJA BAIXÁ-LAS?", "SIM", "NÃO"));
+ }
+ if (flag)
+ {
+ extrato = extrato.Where((DetalheExtrato parcela) => !statusAproximacao.Contains(parcela.Status.Value)).ToList();
+ }
+ List<DetalheExtrato> source = extrato.Where((DetalheExtrato x) => x.Status.HasValue && status.Contains(x.Status.Value)).ToList();
+ if (!source.Any())
+ {
+ SelectedExtrato.Status = (StatusExtrato)3;
+ await _servico.Save(SelectedExtrato);
+ if (_servico.Sucesso)
+ {
+ await ShowMessage("NÃO HÁ PARCELAS A BAIXAR NESSE EXTRATO");
+ }
+ return;
+ }
+ await BaixarExtrato((from x in source
+ orderby x.Cliente, x.Apolice, x.Endosso, ValidationHelper.ToInt(x.NumeroParcela)
+ select x).ToList());
+ }
+ catch (Exception)
+ {
+ }
+ }
+
+ private async Task CarregarImpostos()
+ {
+ Impostos = (await new ImpostoServico().Buscar(true)) ?? new List<Imposto>();
+ }
+
+ public Imposto CarregarImposto(Documento documento)
+ {
+ //IL_008c: Unknown result type (might be due to invalid IL or missing references)
+ object obj = ((IEnumerable<Imposto>)Impostos).FirstOrDefault((Func<Imposto, bool>)((Imposto x) => x.Seguradora != null && ((DomainBase)x.Seguradora).Id == ((DomainBase)documento.Controle.Seguradora).Id && x.Ramo != null && ((DomainBase)x.Ramo).Id == ((DomainBase)documento.Controle.Ramo).Id)) ?? ((IEnumerable<Imposto>)Impostos).FirstOrDefault((Func<Imposto, bool>)((Imposto x) => x.Seguradora != null && ((DomainBase)x.Seguradora).Id == ((DomainBase)documento.Controle.Seguradora).Id && x.Ramo == null));
+ if (obj == null)
+ {
+ obj = ((IEnumerable<Imposto>)Impostos).FirstOrDefault((Func<Imposto, bool>)((Imposto x) => x.Seguradora == null && x.Ramo != null && ((DomainBase)x.Ramo).Id == ((DomainBase)documento.Controle.Ramo).Id));
+ }
+ if (obj == null)
+ {
+ obj = ((IEnumerable<Imposto>)Impostos).FirstOrDefault((Func<Imposto, bool>)((Imposto x) => x.Seguradora == null && x.Ramo == null));
+ }
+ if (obj == null)
+ {
+ obj = (object)new Imposto();
+ }
+ return (Imposto)obj;
+ }
+
+ private async Task BaixarExtrato(List<DetalheExtrato> baixar)
+ {
+ bool atualizarDocumento = true;
+ await CarregarImpostos();
+ _apoliceServico.Sucesso = true;
+ _servico.Sucesso = true;
+ Porcentagem = 0m;
+ Indice = 0m;
+ Total = baixar.Count;
+ List<long> list = (from x in baixar
+ where x.Documento.HasValue
+ select x.Documento.Value).ToList();
+ List<long> parcelasId = (from x in baixar
+ where !x.Documento.HasValue && x.Parcela.HasValue
+ select x.Parcela.Value).ToList();
+ List<Documento> list2 = ((list.Count <= 0) ? new List<Documento>() : (await _apoliceServico.BuscarApolicesPorId(list)));
+ List<Documento> documentos = list2;
+ if (parcelasId.Count > 0)
+ {
+ List<Documento> list3 = documentos;
+ list3.AddRange(await _apoliceServico.BuscarApolicesPorIdParcela(parcelasId));
+ }
+ List<Parcela> todasParcelas = await _parcelaServico.BuscarTodasParcelas(documentos.Select((Documento x) => ((DomainBase)x).Id).ToList());
+ todasParcelas.ForEach(delegate(Parcela p)
+ {
+ p.Documento = documentos.Find((Documento d) => ((DomainBase)d).Id == ((DomainBase)p.Documento).Id);
+ });
+ foreach (DetalheExtrato x2 in baixar)
+ {
+ if (!x2.Documento.HasValue && !x2.Parcela.HasValue)
+ {
+ x2.Status = (StatusParcela)2;
+ await _servico.Save(x2);
+ continue;
+ }
+ Indice++;
+ Porcentagem = Indice * 100m / Total;
+ bool criada = false;
+ Documento documento = null;
+ if (x2.Documento.HasValue && x2.Documento > 0)
+ {
+ documento = documentos.Find((Documento d) => ((DomainBase)d).Id == x2.Documento.Value);
+ }
+ if (documento.Excluido)
+ {
+ x2.Status = (StatusParcela)2;
+ await _servico.Save(x2);
+ continue;
+ }
+ if (documento != null && (int)documento.TipoRecebimento.GetValueOrDefault() == 1 && documento.Comissao == 0m && x2.Parcela.HasValue && x2.Parcela != 999)
+ {
+ Documento obj = documento;
+ if (obj != null && obj.Ordem == 0)
+ {
+ continue;
+ }
+ }
+ bool baixado = true;
+ List<Parcela> parcelas2 = (x2.Documento.HasValue ? (from p in todasParcelas
+ where ((DomainBase)p.Documento).Id == x2.Documento.Value
+ orderby p.NumeroParcela
+ select p).ToList() : null);
+ Parcela parcela;
+ if (!x2.Parcela.HasValue)
+ {
+ List<VendedorParcela> list4 = ((parcelas2.Count <= 0) ? (await _vendedorServico.BuscaRepasse(x2.Documento.Value)) : (await _vendedorServico.BuscaRepasseParcela(((DomainBase)parcelas2.First()).Id)));
+ List<VendedorParcela> list5 = list4;
+ Imposto val = CarregarImposto(documento);
+ decimal num = x2.ValorComissao.GetValueOrDefault() * val.Ir;
+ decimal num2 = x2.ValorComissao.GetValueOrDefault() * val.Iss;
+ decimal num3 = x2.ValorComissao.GetValueOrDefault() * val.Outros;
+ decimal num4 = x2.ValorComissao.GetValueOrDefault() * val.Desconto;
+ decimal valorComDesconto = x2.ValorComissao.GetValueOrDefault() - (num + num2 + num3 + num4);
+ DateTime? dateTime = (((int)documento.TipoRecebimento.GetValueOrDefault() == 1) ? null : ((!x2.Recebimento.HasValue) ? SelectedExtrato.Data : x2.Recebimento));
+ decimal obj3;
+ if ((int)documento.TipoRecebimento.GetValueOrDefault() != 1)
+ {
+ Parcela? obj2 = parcelas2.FirstOrDefault();
+ obj3 = ((obj2 != null) ? obj2.Comissao : x2.Comissao.GetValueOrDefault(100m));
+ }
+ else
+ {
+ obj3 = 100m;
+ }
+ decimal num5 = obj3;
+ if (num5 == 100m && x2.Valor.HasValue && x2.Comissao.HasValue && x2.ValorComissao.HasValue)
+ {
+ decimal value = (x2.Valor * (x2.Comissao / (decimal?)100)).Value;
+ decimal value2 = x2.ValorComissao.Value;
+ if (Math.Truncate(value) == Math.Truncate(value2))
+ {
+ DetalheExtrato obj4 = x2;
+ num5 = ((obj4 != null) ? obj4.Comissao : null).Value;
+ }
+ }
+ Parcela val2 = new Parcela
+ {
+ Documento = documento,
+ Vencimento = Funcoes.GetNetworkTime().Date,
+ Comissao = num5,
+ SubTipo = (SubTipo)(((int)documento.TipoRecebimento.GetValueOrDefault() != 1) ? 1 : ((int)x2.SubTipo.GetValueOrDefault((SubTipo)3)))
+ };
+ int numeroParcela;
+ if ((int)documento.TipoRecebimento.GetValueOrDefault() != 1)
+ {
+ List<Parcela> list6 = parcelas2;
+ int? obj5;
+ if (list6 == null)
+ {
+ obj5 = null;
+ }
+ else
+ {
+ Parcela? obj6 = list6.LastOrDefault();
+ obj5 = ((obj6 != null) ? new int?(obj6.NumeroParcela) : null);
+ }
+ int? num6 = obj5;
+ numeroParcela = num6.GetValueOrDefault() + 1;
+ }
+ else
+ {
+ numeroParcela = 999;
+ }
+ val2.NumeroParcela = numeroParcela;
+ val2.Valor = x2.Valor.GetValueOrDefault();
+ val2.ValorRealizado = x2.Valor.GetValueOrDefault();
+ val2.ValorComissao = x2.ValorComissao.GetValueOrDefault();
+ val2.Irr = num;
+ val2.Iss = num2;
+ val2.Outros = num3;
+ val2.Desconto = num4;
+ val2.ValorComDesconto = valorComDesconto;
+ val2.DataRecebimento = SelectedExtrato.Data;
+ val2.DataCredito = SelectedExtrato.DataCredito ?? SelectedExtrato.Data;
+ val2.Fatura = (((int)documento.TipoRecebimento.GetValueOrDefault() == 1) ? "" : x2.Endosso);
+ val2.Emissao = dateTime;
+ val2.VigenciaIncial = dateTime;
+ val2.VigenciaFinal = (((int)documento.TipoRecebimento.GetValueOrDefault() == 1) ? null : dateTime?.AddMonths(1));
+ val2.Extrato = x2.Extrato.Numero;
+ val2.DataCriacao = DateTime.Now;
+ parcela = val2;
+ if (documento.Ordem > 0)
+ {
+ VendedorServico vendedorServico = _vendedorServico;
+ list5 = Funcoes.DistinctBy(await vendedorServico.BuscaRepasse(((DomainBase)(await _apoliceServico.BuscarControleAsync(((DomainBase)documento.Controle).Id)).Documentos.First((Documento d) => d.Ordem == 0)).Id), (VendedorParcela v) => v.TipoVendedor).ToList();
+ }
+ if (list5 != null)
+ {
+ ExtensionMethods.ForEach<VendedorParcela>(list5.Where((VendedorParcela v) => v.Repasse != null), (Action<VendedorParcela>)delegate(VendedorParcela v)
+ {
+ //IL_0029: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002f: Invalid comparison between Unknown and I4
+ //IL_005c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0061: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0062: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0064: Unknown result type (might be due to invalid IL or missing references)
+ //IL_007e: Expected I4, but got Unknown
+ //IL_00ae: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00b4: Invalid comparison between Unknown and I4
+ //IL_00fd: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0103: Invalid comparison between Unknown and I4
+ //IL_0134: Unknown result type (might be due to invalid IL or missing references)
+ //IL_013a: Invalid comparison between Unknown and I4
+ ((DomainBase)v).Id = 0L;
+ decimal value3 = Funcoes.CalculaRepasse(v.Repasse, parcela, apolice: false);
+ if ((int)v.Repasse.Forma.GetValueOrDefault() == 1)
+ {
+ v.DataPrePagamento = parcela.DataRecebimento;
+ }
+ switch (v.Repasse.Base)
+ {
+ case 2L:
+ v.DataPrePagamento = parcela.Vencimento;
+ break;
+ case 0L:
+ v.DataPrePagamento = (((int)documento.TipoRecebimento.GetValueOrDefault() == 2) ? parcela.VigenciaIncial : new DateTime?(documento.Vigencia1));
+ break;
+ case 1L:
+ v.DataPrePagamento = parcela.DataCriacao;
+ break;
+ case 3L:
+ v.DataPrePagamento = (((int)documento.TipoRecebimento.GetValueOrDefault() == 2) ? parcela.Emissao : documento.Emissao);
+ break;
+ case 4L:
+ v.DataPrePagamento = (((int)documento.TipoRecebimento.GetValueOrDefault() == 2) ? parcela.Emissao : documento.Remessa);
+ break;
+ }
+ v.ValorRepasse = value3;
+ v.ValorTotal = value3;
+ v.DataPagamento = null;
+ });
+ }
+ if (list5 == null || list5.Count == 0)
+ {
+ list5 = new List<VendedorParcela> { PropriaCorretora() };
+ }
+ if ((int)parcela.Documento.TipoRecebimento.GetValueOrDefault() == 1)
+ {
+ parcela.Vendedores = new ObservableCollection<VendedorParcela>(list5);
+ parcela.Extrato = x2.Extrato.Numero;
+ parcela = await _parcelaServico.Save(parcela, Parcelas.ToList(), list5);
+ if (!_parcelaServico.Sucesso)
+ {
+ return;
+ }
+ x2.Parcela = ((DomainBase)parcela).Id;
+ criada = true;
+ }
+ }
+ if (!criada)
+ {
+ if (!x2.Parcela.HasValue)
+ {
+ continue;
+ }
+ parcela = todasParcelas.Find((Parcela p) => ((DomainBase)p).Id == x2.Parcela.Value);
+ if (parcela == null)
+ {
+ continue;
+ }
+ x2.Documento = ((DomainBase)parcela.Documento).Id;
+ if (parcela.DataRecebimento.HasValue)
+ {
+ x2.Status = (StatusParcela)5;
+ await _servico.Save(x2);
+ continue;
+ }
+ List<VendedorParcela> list7 = await _vendedorServico.BuscaRepasseParcela(((DomainBase)parcela).Id);
+ Imposto val3 = CarregarImposto(documento);
+ decimal num7 = x2.ValorComissao.GetValueOrDefault() * val3.Ir;
+ decimal num8 = x2.ValorComissao.GetValueOrDefault() * val3.Iss;
+ decimal num9 = x2.ValorComissao.GetValueOrDefault() * val3.Outros;
+ decimal num10 = x2.ValorComissao.GetValueOrDefault() * val3.Desconto;
+ decimal valorComDesconto2 = x2.ValorComissao.GetValueOrDefault() - (num7 + num8 + num9 + num10);
+ parcela.ValorRealizado = x2.Valor.GetValueOrDefault();
+ parcela.ValorComissao = x2.ValorComissao.GetValueOrDefault();
+ parcela.Irr = num7;
+ parcela.Iss = num8;
+ parcela.Outros = num9;
+ parcela.Desconto = num10;
+ parcela.ValorComDesconto = valorComDesconto2;
+ parcela.DataRecebimento = SelectedExtrato.Data;
+ parcela.DataCredito = SelectedExtrato.DataCredito ?? SelectedExtrato.Data;
+ parcela.Extrato = SelectedExtrato.Numero;
+ parcela.Vendedores = new ObservableCollection<VendedorParcela>(list7);
+ documento = parcela.Documento;
+ parcelas2 = parcelas2 ?? (from p in todasParcelas
+ where ((DomainBase)p.Documento).Id == ((DomainBase)documento).Id
+ orderby p.NumeroParcela
+ select p).ToList();
+ parcelas2.ForEach(delegate(Parcela p)
+ {
+ if (((DomainBase)p).Id == ((DomainBase)parcela).Id)
+ {
+ p.ValorRealizado = parcela.ValorRealizado;
+ p.ValorComissao = parcela.ValorComissao;
+ p.Irr = parcela.Irr;
+ p.Iss = parcela.Iss;
+ p.Outros = parcela.Outros;
+ p.Desconto = parcela.Desconto;
+ p.ValorComDesconto = parcela.ValorComDesconto;
+ p.DataRecebimento = parcela.DataRecebimento;
+ p.DataCredito = parcela.DataCredito ?? parcela.DataRecebimento;
+ p.Extrato = parcela.Extrato;
+ }
+ });
+ bool flag = true;
+ if ((int)parcela.SubTipo == 1)
+ {
+ Parcela val4 = ((IEnumerable<Parcela>)parcelas2).FirstOrDefault((Func<Parcela, bool>)((Parcela p) => !p.DataRecebimento.HasValue));
+ if (val4 != null && val4.NumeroParcela < parcela.NumeroParcela)
+ {
+ x2.Status = (StatusParcela)7;
+ flag = false;
+ baixado = false;
+ }
+ }
+ if (flag)
+ {
+ if (!(await Funcoes.BaixarComissao(parcela, parcelas2, parcela.Vendedores.ToList(), parcela.Documento.Controle.Seguradora.Tolerancia.GetValueOrDefault(), comissaoAuto: true)).DataRecebimento.HasValue)
+ {
+ continue;
+ }
+ Documento documento2 = parcela.Documento;
+ string descricao = ((documento2 != null && (int)documento2.TipoRecebimento.GetValueOrDefault() == 1) ? $"PARCELA {parcela.NumeroParcela} BAIXADA POR COMISSÃO AUTOMÁTICA, EXTRATO {x2.Extrato.Numero}" : ("FATURA " + parcela.Fatura + " BAIXADA POR COMISSÃO AUTOMÁTICA, EXTRATO " + x2.Extrato.Numero));
+ RegistroAcao log = new RegistroAcao
+ {
+ Descricao = descricao,
+ EntidadeId = ((DomainBase)parcela).Id,
+ Tela = (TipoTela)35
+ };
+ string text = ((documento.Tipo == 0) ? ("APÓLICE: " + x2.Apolice) : (((int)documento.TipoRecebimento.GetValueOrDefault() == 2) ? ("APÓLICE: " + x2.Apolice + Environment.NewLine + "FATURA: " + x2.Endosso) : ("APÓLICE: " + x2.Apolice + Environment.NewLine + "ENDOSSO: " + x2.Endosso)));
+ string obs = $"CLIENTE: {x2.Cliente}{Environment.NewLine}{text}{Environment.NewLine}PARCELA: {x2.NumeroParcela}, VALOR: {x2.Valor:c2} COMISSÃO: {x2.Comissao:N2}% VALOR COMISSÃO: {x2.ValorComissao:c2}";
+ _parcelaServico.SalvarAcao(log, obs);
+ }
+ }
+ if (x2.Corrigir && !(await _apoliceServico.AtualizarNumero(((DomainBase)documento).Id, x2.Apolice, x2.Endosso, documento.Tipo)))
+ {
+ atualizarDocumento = false;
+ }
+ StatusParcela? status = x2.Status;
+ if (!status.HasValue)
+ {
+ goto IL_19b4;
+ }
+ StatusParcela valueOrDefault = status.GetValueOrDefault();
+ if ((int)valueOrDefault != 4)
+ {
+ if ((int)valueOrDefault != 14)
+ {
+ goto IL_19b4;
+ }
+ x2.Status = (StatusParcela)13;
+ }
+ else
+ {
+ x2.Status = (StatusParcela)10;
+ }
+ goto IL_1a7e;
+ IL_19b4:
+ x2.Status = (baixado ? new StatusParcela?((StatusParcela)1) : x2.Status);
+ goto IL_1a7e;
+ IL_1a7e:
+ await _servico.Save(x2);
+ if (!_servico.Sucesso)
+ {
+ return;
+ }
+ }
+ SelectedExtrato.Status = (StatusExtrato)3;
+ await _servico.Save(SelectedExtrato);
+ if (!atualizarDocumento)
+ {
+ await ShowMessage("OCORREU UM ERRO AO ATUALIZAR O NÚMERO DA APÓLICE/ENDOSSO DOS DOCUMENTOS BAIXADOS.");
+ }
+ }
+
+ internal async Task<List<Documento>> FiltrarApolices(string value)
+ {
+ return await Task.Run(() => FiltrarDocumento(value));
+ }
+
+ public List<Documento> FiltrarDocumento(string filter)
+ {
+ Apolices = (string.IsNullOrWhiteSpace(filter) ? TodasApolices : new ObservableCollection<Documento>(TodasApolices.Where((Documento x) => (x.Apolice != null && x.Apolice.ToUpper().Contains(filter.ToUpper())) || (x.Endosso != null && x.Endosso.ToUpper().Contains(filter.ToUpper())) || x.Vigencia1.ToString("d").Contains(filter) || (x.Vigencia2.HasValue && x.Vigencia2.Value.ToString("d").Contains(filter)))));
+ SelectedDocumento = null;
+ SelectedParcela = null;
+ return Apolices?.ToList();
+ }
+
+ public async Task BaixarTodosExtratos()
+ {
+ if (Extratos == null || Extratos.Count == 0)
+ {
+ return;
+ }
+ StatusExtrato statusAtual = Extratos[0].Status;
+ PorcentagemExtrato = 0m;
+ IndiceTotal = 0m;
+ TotalExtratos = Extratos.Count;
+ List<StatusParcela> status = new List<StatusParcela>
+ {
+ (StatusParcela)9,
+ (StatusParcela)14,
+ (StatusParcela)16,
+ (StatusParcela)4,
+ (StatusParcela)17,
+ (StatusParcela)15,
+ (StatusParcela)18
+ };
+ await Task.Run(async delegate
+ {
+ foreach (Extrato extrato in Extratos.OrderBy((Extrato x) => x.Data))
+ {
+ decimal indiceTotal = IndiceTotal;
+ IndiceTotal = indiceTotal + 1m;
+ PorcentagemExtrato = IndiceTotal * 100m / TotalExtratos;
+ List<DetalheExtrato> source = (await CarregarDetalhes(extrato)).Where((DetalheExtrato x) => x.Status.HasValue && status.Contains(x.Status.Value)).ToList();
+ SelectedExtrato = extrato;
+ await BaixarExtrato((from x in source
+ orderby x.Cliente, x.Apolice, x.Endosso, x.NumeroParcela
+ select x).ToList());
+ }
+ });
+ SelecionaSeguradora(SelectedSeguradora, statusAtual);
+ ToggleSnackBar("EXTRATOS BAIXADOS COM SUCESSO");
+ }
+
+ public async Task ExcluirExtrato()
+ {
+ if (SelectedExtrato == null)
+ {
+ return;
+ }
+ List<StatusParcela> status = new List<StatusParcela>
+ {
+ (StatusParcela)1,
+ (StatusParcela)10,
+ (StatusParcela)13
+ };
+ try
+ {
+ if (DetalheExtrato.Any((DetalheExtrato x) => x.Status.HasValue && status.Contains(x.Status.Value)))
+ {
+ await ShowMessage("O EXTRATO NÃO PODE SER EXCLUÍDO POIS FOI UTILIZADO PARA BAIXAR PARCELAS, DESFAÇA O EXTRATO ANTES DE EXCLUÍ-LO");
+ }
+ else if (await _servico.Delete(SelectedExtrato))
+ {
+ RegistrarAcao($"EXCLUIU EXTRATO DE ID \n{((DomainBase)SelectedExtrato).Id}\n", ((DomainBase)SelectedExtrato).Id, (TipoTela)35);
+ SelectedExtrato = null;
+ SelecionaSeguradora(SelectedSeguradora, (StatusExtrato)1);
+ ToggleSnackBar("EXTRATO EXCLUÍDO COM SUCESSO");
+ }
+ }
+ catch (Exception)
+ {
+ }
+ }
+
+ public async Task<bool> DesfazerParcela(DetalheExtrato detalhe)
+ {
+ DetalheExtrato obj = detalhe;
+ if (obj == null || !obj.Parcela.HasValue)
+ {
+ return false;
+ }
+ try
+ {
+ Parcela parcela = await _parcelaServico.BuscarParcela(detalhe.Parcela.Value);
+ if (parcela == null)
+ {
+ detalhe.Documento = null;
+ detalhe.Parcela = null;
+ detalhe.Status = (StatusParcela)2;
+ await _servico.Save(detalhe);
+ return false;
+ }
+ detalhe.Documento = ((DomainBase)parcela.Documento).Id;
+ parcela.Extrato = null;
+ List<Parcela> parcelas = await _parcelaServico.BuscarParcelas(detalhe.Documento.Value);
+ Parcela ultimaBaixa = ((IEnumerable<Parcela>)parcelas.OrderByDescending((Parcela p) => p.NumeroParcela)).FirstOrDefault((Func<Parcela, bool>)((Parcela p) => p.DataRecebimento.HasValue && (int)p.SubTipo == 1));
+ bool flag = await _parcelaServico.TemPagamento(((DomainBase)parcela).Id);
+ if ((int)parcela.Documento.TipoRecebimento.GetValueOrDefault() == 1 || !Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 28))
+ {
+ flag = flag || (ultimaBaixa != null && ultimaBaixa.NumeroParcela > parcela.NumeroParcela);
+ }
+ if (flag && !parcela.Documento.Excluido)
+ {
+ return false;
+ }
+ await Funcoes.ExcluirBaixa(parcela, await _vendedorServico.BuscaRepasse(detalhe.Documento.Value), parcelas);
+ Parcela val = ((IEnumerable<Parcela>)parcelas).FirstOrDefault((Func<Parcela, bool>)((Parcela x) => x.NumeroParcela == int.Parse(detalhe.NumeroParcela) - 1));
+ DetalheExtrato obj2 = detalhe;
+ int num;
+ if (val == null || val.DataRecebimento.HasValue)
+ {
+ if ((int)detalhe.Status.GetValueOrDefault() != 13)
+ {
+ if (detalhe.Comissao.HasValue)
+ {
+ decimal comissao = parcela.Documento.Comissao;
+ decimal? comissao2 = detalhe.Comissao;
+ if (!((comissao == comissao2.GetValueOrDefault()) & comissao2.HasValue))
+ {
+ num = 4;
+ goto IL_0578;
+ }
+ }
+ num = 9;
+ }
+ else
+ {
+ num = 14;
+ }
+ }
+ else
+ {
+ num = 7;
+ }
+ goto IL_0578;
+ IL_0578:
+ obj2.Status = (StatusParcela)num;
+ await _servico.Save(detalhe);
+ return true;
+ }
+ catch (Exception e)
+ {
+ new BaseServico().Registrar(e, (TipoErro)292, 3, detalhe);
+ return false;
+ }
+ }
+
+ public async Task DesfazerExtrato()
+ {
+ if (DetalheExtrato == null || DetalheExtrato.Count == 0)
+ {
+ return;
+ }
+ List<StatusParcela> status = new List<StatusParcela>
+ {
+ (StatusParcela)1,
+ (StatusParcela)10,
+ (StatusParcela)12,
+ (StatusParcela)13
+ };
+ List<DetalheExtrato> detalhes = DetalheExtrato.Where((DetalheExtrato x) => x.Status.HasValue && status.Contains(x.Status.Value)).ToList();
+ if (detalhes.Count == 0)
+ {
+ await ShowMessage("NÃO HÁ PARCELAS PARA SEREM DESFEITAS NO EXTRATO");
+ return;
+ }
+ Porcentagem = 0m;
+ Indice = 0m;
+ Total = detalhes.Count;
+ List<DetalheExtrato> log = new List<DetalheExtrato>();
+ await Task.Run(async delegate
+ {
+ foreach (DetalheExtrato detalhe in from x in detalhes
+ orderby x.Cliente, x.Apolice, x.Endosso, x.NumeroParcela descending
+ select x)
+ {
+ decimal indice = Indice;
+ Indice = indice + 1m;
+ Porcentagem = Indice * 100m / Total;
+ if (!(await DesfazerParcela(detalhe)))
+ {
+ log.Add(detalhe);
+ }
+ }
+ });
+ SelectedExtrato.Status = (StatusExtrato)1;
+ await _servico.Save(SelectedExtrato);
+ if (_servico.Sucesso)
+ {
+ ObservableCollection<DetalheExtrato> detalhesAtualizados = await CarregarDetalhes(SelectedExtrato);
+ if (log.Count > 0)
+ {
+ await ShowDetalheExtrato(log);
+ }
+ else
+ {
+ ToggleSnackBar("EXTRATO DESFEITO COM SUCESSO");
+ }
+ RegistrarAcao($"DESFEZ EXTRATO DE ID \n{((DomainBase)SelectedExtrato).Id}\n", ((DomainBase)SelectedExtrato).Id, (TipoTela)35);
+ bool flag = !detalhesAtualizados.Any((DetalheExtrato x) => x.Status.HasValue && status.Contains(x.Status.Value));
+ if (flag)
+ {
+ flag = await ShowMessage("DESEJA EXCLUIR O EXTRATO DESFEITO?", "SIM", "NÃO");
+ }
+ if (flag)
+ {
+ await ExcluirExtrato();
+ SelectedExtrato = null;
+ }
+ Carregando = true;
+ SelectedStatusExtrato = (StatusExtrato)1;
+ Carregando = false;
+ SelecionaSeguradora(SelectedSeguradora, SelectedStatusExtrato, SelectedExtrato);
+ }
+ }
+
+ public void AdcionarFiltro()
+ {
+ if (!string.IsNullOrEmpty(Filtro))
+ {
+ if (FiltroPersonalizado == null)
+ {
+ FiltroPersonalizado = new ObservableCollection<string>();
+ }
+ FiltroPersonalizado.Add(Filtro);
+ Filtro = string.Empty;
+ FiltrarExtrato();
+ }
+ }
+
+ public void FiltrarExtrato()
+ {
+ ExtratosFiltrados = new ObservableCollection<Extrato>(Filtrar());
+ SelectedExtrato = ExtratosFiltrados.FirstOrDefault();
+ ObservableCollection<Extrato> extratosFiltrados = ExtratosFiltrados;
+ IsExpanded = extratosFiltrados != null && extratosFiltrados.Count > 0;
+ }
+
+ private List<Extrato> Filtrar()
+ {
+ List<Extrato> extratos = Extratos.ToList();
+ FiltroPersonalizado.ToList().ForEach(delegate(string f)
+ {
+ extratos = (from x in extratos
+ where ValidationHelper.RemoveDiacritics(x.Seguradora.Nome).ToUpper().Contains(ValidationHelper.RemoveDiacritics(f)) || ValidationHelper.RemoveDiacritics(x.Numero).ToUpper().Contains(ValidationHelper.RemoveDiacritics(f)) || (x.Data.HasValue && x.Data.ToString().Contains(f)) || (x.Bruto.HasValue && x.Bruto.ToString().Contains(f)) || (x.Liquido.HasValue && x.Liquido.ToString().Contains(f)) || (x.DataCredito.HasValue && x.DataCredito.ToString().Contains(f))
+ orderby x.Numero, x.DataCredito descending
+ select x).ToList();
+ });
+ return extratos;
+ }
+
+ public void ExcluirFiltro(string filtro)
+ {
+ FiltroPersonalizado.Remove(filtro);
+ FiltrarExtrato();
+ }
+
+ public async Task CriticarTodos(long id)
+ {
+ ObservableCollection<DetalheExtrato> parcelas = await _servico.BuscarDetalhes(id);
+ foreach (DetalheExtrato item in parcelas)
+ {
+ if ((int)item.Status.GetValueOrDefault() == 2 || (int)item.Status.GetValueOrDefault() == 3)
+ {
+ item.Status = (StatusParcela)6;
+ await _servico.Save(item);
+ if (!_servico.Sucesso)
+ {
+ return;
+ }
+ }
+ }
+ if (parcelas.All((DetalheExtrato x) => (int)x.Status.GetValueOrDefault() == 6))
+ {
+ SelectedExtrato.Status = (StatusExtrato)3;
+ SelectedStatusExtrato = (StatusExtrato)3;
+ await SelecionaExtrato(SelectedExtrato);
+ }
+ await CarregaDetalhes(SelectedExtrato);
+ ToggleSnackBar("CRÍTICA REALIZADA COM SUCESSO");
+ RegistrarAcao($"DESCONSIDEROU TODAS AS PARCELAS COM O STATUS DE DOCUMENTO NÃO ENCONTRADO OU PARCELA NÃO ENCONTRADA DO EXTRATO DE ID \n{id}\n", id, (TipoTela)35);
+ }
+
+ public async Task<string> GerarHtml()
+ {
+ ExtratoComissao val = new ExtratoComissao();
+ Usuario? obj = ((IEnumerable<Usuario>)Auxiliar.Usuarios).FirstOrDefault((Func<Usuario, bool>)((Usuario x) => ((DomainBase)x).Id == SelectedExtrato.IdUsuario));
+ val.Usuario = ((obj != null) ? obj.Nome : null);
+ val.Seguradora = SelectedExtrato.Seguradora.Nome;
+ val.DetalhesExtrato = new ObservableCollection<DetalhesExtrato>();
+ val.InformacoesExtrato = new ObservableCollection<InformacoesExtrato>
+ {
+ new InformacoesExtrato
+ {
+ NumeroExtrato = SelectedExtrato.Numero,
+ DataExtrato = SelectedExtrato.Data,
+ Bruto = SelectedExtrato.Bruto.GetValueOrDefault(),
+ Liquido = SelectedExtrato.Liquido.GetValueOrDefault(),
+ Ir = SelectedExtrato.Ir.GetValueOrDefault(),
+ Iss = SelectedExtrato.Iss.GetValueOrDefault(),
+ Outros = SelectedExtrato.Outro.GetValueOrDefault(),
+ Quantidade = Quantidade,
+ TotalBaixado = TotalBaixado,
+ TotalPendente = TotalPendente
+ }
+ };
+ ExtratoComissao extrato = val;
+ foreach (DetalheExtrato detalheExtratoFiltrado in DetalheExtratoFiltrados)
+ {
+ DetalhesExtrato item = new DetalhesExtrato
+ {
+ Cliente = detalheExtratoFiltrado.Cliente,
+ Apolice = detalheExtratoFiltrado.Apolice,
+ Endosso = detalheExtratoFiltrado.Endosso,
+ Parcela = detalheExtratoFiltrado.NumeroParcela,
+ Pagto = detalheExtratoFiltrado.Valor,
+ Comissao = detalheExtratoFiltrado.Comissao,
+ ValorComissao = detalheExtratoFiltrado.ValorComissao,
+ Status = ValidationHelper.GetDescription((Enum)(object)detalheExtratoFiltrado.Status)
+ };
+ extrato.DetalhesExtrato.Add(item);
+ }
+ string body = await Funcoes.GenerateTable(extrato.InformacoesExtrato.ToList(), new List<string>()) + await Funcoes.GenerateTable(extrato.DetalhesExtrato.ToList(), new List<string>());
+ string text = Funcoes.CreateCard("<b>SEGURADORA:</b> " + extrato.Seguradora + "<br><b>USUÁRIO IMPORTAÇÃO:</b> " + extrato.Usuario, body);
+ return Funcoes.ExportarHtml(new TipoRelatorio
+ {
+ Nome = "EXTRATO DE COMISSÃO"
+ }, text ?? "", "70");
+ }
+
+ public async Task FinalizarExtrato()
+ {
+ if (DetalheExtrato != null && DetalheExtrato.Count != 0)
+ {
+ StatusExtrato extrato = SelectedStatusExtrato;
+ SelectedExtrato.Status = (StatusExtrato)3;
+ Extrato val = await _servico.Save(SelectedExtrato);
+ if (_servico.Sucesso)
+ {
+ SelectedExtrato = null;
+ SelecionaSeguradora(SelectedSeguradora, extrato);
+ ToggleSnackBar("EXTRATO FINALIZADO COM SUCESSO");
+ RegistrarAcao($"FINALIZOU EXTRATO DE ID \n{((DomainBase)val).Id}\n", ((DomainBase)val).Id, (TipoTela)35);
+ }
+ }
+ }
+
+ public async Task DesconsiderarSelecionadas()
+ {
+ if (DetalheExtrato == null || DetalheExtrato.Count == 0)
+ {
+ return;
+ }
+ List<StatusParcela> statusBaixados = new List<StatusParcela>
+ {
+ (StatusParcela)1,
+ (StatusParcela)5,
+ (StatusParcela)8,
+ (StatusParcela)10,
+ (StatusParcela)12,
+ (StatusParcela)13,
+ (StatusParcela)21,
+ (StatusParcela)8,
+ (StatusParcela)6
+ };
+ IEnumerable<DetalheExtrato> enumerable = DetalheExtrato.Where((DetalheExtrato parcelas) => parcelas.Selecionado);
+ if (!enumerable.Any((DetalheExtrato parcelas) => statusBaixados.Any((StatusParcela status) => (StatusParcela?)status == parcelas.Status)))
+ {
+ foreach (DetalheExtrato item in enumerable)
+ {
+ item.Status = (StatusParcela)6;
+ await _servico.Save(item);
+ if (!_servico.Sucesso)
+ {
+ return;
+ }
+ }
+ await CarregaDetalhes(SelectedExtrato);
+ }
+ else
+ {
+ await ShowMessage("HÁ PARCELAS SELECIONADAS QUE JÁ ESTÃO BAIXADAS OU JÁ DESCONSIDERADAS");
+ }
+ }
+}