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.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; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows; 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 _seguradoras = new ObservableCollection(); private DateTime _inicio; private DateTime _fim; private bool _baixarPendentes; private ObservableCollection _extratos; private ObservableCollection _extratosFiltrados; private Extrato _selectedExtrato; private ObservableCollection _usuarios; private Usuario _selectedUsuario; private List _statusExtrato; private StatusExtrato _selectedStatusExtrato; private Seguradora _selectedSeguradora; private Gestor.Model.Domain.Seguros.DetalheExtrato _selectedDetalhe; private FiltroStatusDocumento _selectedStatus; private Cliente _selectedCliente; private string _documentoPrincipal; private ObservableCollection _detalheExtrato; private bool _allSelected; private ObservableCollection _detalheExtratoFiltrados; private int _quantidade; private decimal _totalBaixado; private decimal _totalPendente; private Visibility _isVisibleCliente; private Visibility _isVisibleApolice; private Visibility _isVisibleMensagem; private Visibility _isVisibleDetalhes; private Visibility _isVisibleExtrato; private bool _isExpanded; private ObservableCollection _apolices; private bool _idFatura; private Documento _selectedDocumento; private Parcela _selectedParcela; private ObservableCollection _parcelas; 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 _filtroPersonalizado; private bool _carregadoDetalhes { get; set; } public bool AllSelected { get { return this._allSelected; } set { this._allSelected = value; base.OnPropertyChanged("AllSelected"); if (this._carregadoDetalhes) { return; } this.Selecionar(value); } } public bool Apelido { get { return this._apelido; } set { this._apelido = value; base.OnPropertyChanged("Apelido"); } } public ObservableCollection Apolices { get { return this._apolices; } set { this._apolices = value; base.OnPropertyChanged("Apolices"); } } public bool BaixarPendentes { get { return this._baixarPendentes; } set { this._baixarPendentes = value; base.OnPropertyChanged("BaixarPendentes"); } } public bool BaixarVisibility { get { return this._baixarVisibility; } set { this._baixarVisibility = value; base.OnPropertyChanged("BaixarVisibility"); } } public bool Buscando { get; set; } private bool Carregando { get; set; } public bool Criticando { get { return this._criticando; } set { this._criticando = value; base.OnPropertyChanged("Criticando"); } } public bool DesconsiderarVisibility { get { return this._desconsiderarVisibility; } set { this._desconsiderarVisibility = value; base.OnPropertyChanged("DesconsiderarVisibility"); } } public bool DesfazerVisibility { get { return this._desfazerVisibility; } set { this._desfazerVisibility = value; base.OnPropertyChanged("DesfazerVisibility"); } } public ObservableCollection DetalheExtrato { get { return this._detalheExtrato; } set { bool hasValue; decimal zero; this._detalheExtrato = value; this.Quantidade = (value != null ? value.Count : 0); List statusParcelas = new List() { 1, 10, 13 }; this.TotalBaixado = (value != null ? value.Where((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue || !x.get_ValorComissao().HasValue) { return false; } return statusParcelas.Contains(x.get_Status().Value); }).Sum((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_ValorComissao().Value) : decimal.Zero); Extrato selectedExtrato = this.SelectedExtrato; if (selectedExtrato != null) { hasValue = selectedExtrato.get_Bruto().HasValue; } else { hasValue = false; } if (hasValue) { decimal? bruto = this.SelectedExtrato.get_Bruto(); zero = bruto.Value - this.TotalBaixado; } else { zero = decimal.Zero; } this.TotalPendente = zero; base.OnPropertyChanged("DetalheExtrato"); } } public ObservableCollection DetalheExtratoFiltrados { get { return this._detalheExtratoFiltrados; } set { this._detalheExtratoFiltrados = value; base.OnPropertyChanged("DetalheExtratoFiltrados"); } } public string DocumentoPrincipal { get { return this._documentoPrincipal; } set { this._documentoPrincipal = value; base.OnPropertyChanged("DocumentoPrincipal"); } } public ObservableCollection Extratos { get { return this._extratos; } set { this._extratos = value; if (value == null || value.Count == 0) { this.DetalheExtrato = null; this.DetalheExtratoFiltrados = null; } base.OnPropertyChanged("Extratos"); } } public ObservableCollection ExtratosFiltrados { get { return this._extratosFiltrados; } set { bool id; this._extratosFiltrados = value; this.BaixarPendentes = (value == null ? false : value.Count > 0); if (value == null || value.Count <= 0) { id = false; } else { Usuario usuario = Recursos.Usuario; if (usuario != null) { id = usuario.get_Id() > (long)0; } else { id = false; } } base.EnableButtons = id; this.IsVisibleExtrato = (value == null || value.Count <= 0 ? Visibility.Collapsed : Visibility.Visible); base.OnPropertyChanged("ExtratosFiltrados"); } } public string Filtro { get { return this._filtro; } set { this._filtro = value; base.OnPropertyChanged("Filtro"); } } public string FiltroApolice { get { return this._filtroApolice; } set { this._filtroApolice = value; base.OnPropertyChanged("FiltroApolice"); } } public ObservableCollection FiltroPersonalizado { get { return this._filtroPersonalizado; } set { this._filtroPersonalizado = value; base.OnPropertyChanged("FiltroPersonalizado"); } } public DateTime Fim { get { return this._fim; } set { this._fim = value; base.OnPropertyChanged("Fim"); } } public bool FinalizarVisibility { get { return this._finalizarVisibility; } set { this._finalizarVisibility = value; base.OnPropertyChanged("FinalizarVisibility"); } } private List Impostos { get; set; } public decimal Indice { get { return this._indice; } set { this._indice = value; base.OnPropertyChanged("Indice"); } } public decimal IndiceTotal { get { return this._indiceTotal; } set { this._indiceTotal = value; base.OnPropertyChanged("IndiceTotal"); } } public DateTime Inicio { get { return this._inicio; } set { this._inicio = value; base.OnPropertyChanged("Inicio"); } } public bool IsExpanded { get { return this._isExpanded; } set { this._isExpanded = value; base.OnPropertyChanged("IsExpanded"); } } public bool IsFatura { get { return this._idFatura; } set { this._idFatura = value; base.OnPropertyChanged("IsFatura"); } } public Visibility IsVisibleApolice { get { return this._isVisibleApolice; } set { this._isVisibleApolice = value; base.OnPropertyChanged("IsVisibleApolice"); } } public Visibility IsVisibleCliente { get { return this._isVisibleCliente; } set { this._isVisibleCliente = value; base.OnPropertyChanged("IsVisibleCliente"); } } public Visibility IsVisibleDetalhes { get { return this._isVisibleDetalhes; } set { this._isVisibleDetalhes = value; base.OnPropertyChanged("IsVisibleDetalhes"); } } public Visibility IsVisibleExtrato { get { return this._isVisibleExtrato; } set { this._isVisibleExtrato = value; base.OnPropertyChanged("IsVisibleExtrato"); } } public Visibility IsVisibleMensagem { get { return this._isVisibleMensagem; } set { this._isVisibleMensagem = value; base.OnPropertyChanged("IsVisibleMensagem"); } } public ObservableCollection Parcelas { get { return this._parcelas; } set { this._parcelas = value; base.OnPropertyChanged("Parcelas"); } } public string PesquisaPagamento { get { return this._pesquisaPagamento; } set { this._pesquisaPagamento = value; base.OnPropertyChanged("PesquisaPagamento"); } } public decimal Porcentagem { get { return this._porcentagem; } set { this._porcentagem = value; base.OnPropertyChanged("Porcentagem"); } } public decimal PorcentagemExtrato { get { return this._porcentagemExtrato; } set { this._porcentagemExtrato = value; base.OnPropertyChanged("PorcentagemExtrato"); } } public int Quantidade { get { return this._quantidade; } set { this._quantidade = value; base.OnPropertyChanged("Quantidade"); } } public ObservableCollection Seguradoras { get { return this._seguradoras; } set { this._seguradoras = value; this.SelectedSeguradora = this.SelectedSeguradora ?? value.FirstOrDefault(); base.OnPropertyChanged("Seguradoras"); } } public Cliente SelectedCliente { get { return this._selectedCliente; } set { this.WorkOnSelectedCliente(value); this._selectedCliente = value; base.OnPropertyChanged("SelectedCliente"); } } public Gestor.Model.Domain.Seguros.DetalheExtrato SelectedDetalhe { get { return this._selectedDetalhe; } set { this._selectedDetalhe = value; base.OnPropertyChanged("SelectedDetalhe"); } } public Documento SelectedDocumento { get { return this._selectedDocumento; } set { this._selectedDocumento = value; this.WorkOnSelectedDocumento(value); base.OnPropertyChanged("SelectedDocumento"); } } public Extrato SelectedExtrato { get { return this._selectedExtrato; } set { this._selectedExtrato = value; this.IsVisibleExtrato = (value != null ? Visibility.Visible : Visibility.Collapsed); base.OnPropertyChanged("SelectedExtrato"); } } public Parcela SelectedParcela { get { return this._selectedParcela; } set { this._selectedParcela = value; base.OnPropertyChanged("SelectedParcela"); } } public Seguradora SelectedSeguradora { get { return this._selectedSeguradora; } set { this._selectedSeguradora = value; this.FiltroPersonalizado = new ObservableCollection(); this.SelecionaSeguradora(value, this.SelectedStatusExtrato, null); base.OnPropertyChanged("SelectedSeguradora"); } } public FiltroStatusDocumento SelectedStatus { get { return this._selectedStatus; } set { this._selectedStatus = value; this.WorkOnSelectedStatus(); base.OnPropertyChanged("SelectedStatus"); } } public StatusExtrato SelectedStatusExtrato { get { return this._selectedStatusExtrato; } set { this._selectedStatusExtrato = value; this.SelecionaSeguradora(this.SelectedSeguradora, value, null); base.OnPropertyChanged("SelectedStatusExtrato"); } } public Usuario SelectedUsuario { get { return this._selectedUsuario; } set { this._selectedUsuario = value; this.SelecionaSeguradora(this.SelectedSeguradora, this.SelectedStatusExtrato, null); base.OnPropertyChanged("SelectedUsuario"); } } public List Status { get { return this._statusExtrato; } set { this._statusExtrato = value; base.OnPropertyChanged("Status"); } } public ObservableCollection TodasApolices { get; set; } public decimal Total { get { return this._total; } set { this._total = value; base.OnPropertyChanged("Total"); } } public decimal TotalBaixado { get { return this._totalBaixado; } set { this._totalBaixado = value; base.OnPropertyChanged("TotalBaixado"); } } public decimal TotalExtratos { get { return this._totaExtratosl; } set { this._totaExtratosl = value; base.OnPropertyChanged("TotalExtratos"); } } public decimal TotalPendente { get { return this._totalPendente; } set { this._totalPendente = value; base.OnPropertyChanged("TotalPendente"); } } public ObservableCollection Usuarios { get { return this._usuarios; } set { this._usuarios = value; this.SelectedUsuario = this.SelectedUsuario ?? value.FirstOrDefault(); base.OnPropertyChanged("Usuarios"); } } public ComissaoViewModel() { this._seguradoras = new ObservableCollection(); DateTime date = Funcoes.GetNetworkTime().Date; int year = date.Year; date = Funcoes.GetNetworkTime().Date; this._inicio = new DateTime(year, date.Month, 1); this._fim = Funcoes.GetNetworkTime().Date; this._baixarPendentes = true; this._extratos = new ObservableCollection(); this._extratosFiltrados = new ObservableCollection(); this._usuarios = new ObservableCollection(); this._statusExtrato = new List() { 1, 2, 3, 4 }; this._selectedStatusExtrato = 1; this._documentoPrincipal = ""; this._isVisibleCliente = Visibility.Collapsed; this._isVisibleApolice = Visibility.Collapsed; this._isVisibleMensagem = Visibility.Collapsed; this._isVisibleDetalhes = Visibility.Collapsed; this._isVisibleExtrato = Visibility.Collapsed; this._isExpanded = true; this._apolices = new ObservableCollection(); this._selectedDocumento = new Documento(); this._selectedParcela = new Parcela(); this._parcelas = new ObservableCollection(); this.Impostos = new List(); this._filtro = ""; this._pesquisaPagamento = ""; this._filtroApolice = ""; this._filtroPersonalizado = new ObservableCollection(); base(); this._servico = new ServicoExtrato(); this._apoliceServico = new ApoliceServico(); this._parcelaServico = new ParcelaServico(); this._vendedorServico = new VendedorServico(); this.Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 6); this.SelecionaSeguradoras(); base.EnableMenu = true; } public void AdcionarFiltro() { if (string.IsNullOrEmpty(this.Filtro)) { return; } if (this.FiltroPersonalizado == null) { this.FiltroPersonalizado = new ObservableCollection(); } this.FiltroPersonalizado.Add(this.Filtro); this.Filtro = string.Empty; this.FiltrarExtrato(); } public async Task AtualizarExtrato() { if (this.DetalheExtratoFiltrados != null && this.DetalheExtratoFiltrados.Count != 0) { ObservableCollection detalheExtratoFiltrados = this.DetalheExtratoFiltrados; if (!detalheExtratoFiltrados.All((Gestor.Model.Domain.Seguros.DetalheExtrato x) => !x.get_Selecionado())) { base.Loading(true); this.IsVisibleDetalhes = Visibility.Collapsed; base.IsVisible = Visibility.Collapsed; ParcelaServico parcelaServico = this._parcelaServico; ObservableCollection observableCollection = this.DetalheExtratoFiltrados; await parcelaServico.UpdateDetalhes(( from x in observableCollection where x.get_Selecionado() select x).ToList()); base.IsVisible = Visibility.Visible; this.IsVisibleDetalhes = Visibility.Visible; base.Loading(false); base.RegistrarAcao(string.Format("ATUALIZOU EXTRATO DE ID \n{0}\n", this.SelectedExtrato.get_Id()), this.SelectedExtrato.get_Id(), new TipoTela?(35), null); base.ToggleSnackBar("EXTRATO ATUALIZADO COM SUCESSO", true); } else { await base.ShowMessage("NECESSÁRIO SELECIONAR QUAL PARCELA DESEJA ATUALIZAR.", "OK", "", false); } } } private async Task BaixarComissao(List extrato, bool selecionados = false) { bool flag; try { List statusParcelas = new List() { 9, 14, 16, 4, 17, 15, 7, 18 }; List statusParcelas1 = statusParcelas; List statusParcelas2 = new List() { 16, 18 }; flag = (selecionados ? false : this.DetalheExtrato.ToList().Any((Gestor.Model.Domain.Seguros.DetalheExtrato x) => statusParcelas2.Contains(x.get_Status().Value))); bool flag1 = flag; if (flag1) { flag1 = !await base.ShowMessage("O EXTRATO CONTÉM PARCELAS ENCONTRADAS POR APROXIMAÇÃO, DESEJA BAIXÁ-LAS?", "SIM", "NÃO", false); } if (flag1) { extrato = ( from parcela in extrato where !statusParcelas2.Contains(parcela.get_Status().Value) select parcela).ToList(); } List list = extrato.Where((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas1.Contains(x.get_Status().Value); }).ToList(); if (list.Any()) { ComissaoViewModel comissaoViewModel = this; List detalheExtratos = list; IOrderedEnumerable cliente = from x in detalheExtratos orderby x.get_Cliente() select x; IOrderedEnumerable detalheExtratos1 = cliente.ThenBy((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Apolice()); IOrderedEnumerable detalheExtratos2 = detalheExtratos1.ThenBy((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Endosso()); await comissaoViewModel.BaixarExtrato(detalheExtratos2.ThenBy((Gestor.Model.Domain.Seguros.DetalheExtrato x) => ValidationHelper.ToInt(x.get_NumeroParcela())).ToList()); } else { this.SelectedExtrato.set_Status(3); await this._servico.Save(this.SelectedExtrato); if (this._servico.Sucesso) { await base.ShowMessage("NÃO HÁ PARCELAS A BAIXAR NESSE EXTRATO", "OK", "", false); return; } else { return; } } } catch (Exception exception) { } } public async Task BaixarExtrato(bool selecionados = false) { List list; if (this.DetalheExtrato != null && this.DetalheExtrato.Count != 0) { List detalheExtratos = this.DetalheExtrato.ToList(); if (!detalheExtratos.All((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Status().GetValueOrDefault() == 6)) { StatusExtrato status = this.SelectedExtrato.get_Status(); if (selecionados) { ObservableCollection detalheExtrato = this.DetalheExtrato; list = ( from x in detalheExtrato where x.get_Selecionado() select x).ToList(); } else { list = this.DetalheExtrato.ToList(); } await this.BaixarComissao(list, selecionados); base.RegistrarAcao(string.Format("BAIXOU EXTRATO DE ID \n{0}\n", this.SelectedExtrato.get_Id()), this.SelectedExtrato.get_Id(), new TipoTela?(35), null); if (this.SelectedExtrato.get_Status() != 3) { this.SelectedStatusExtrato = this.SelectedExtrato.get_Status(); } this.SelectedExtrato = null; this.SelecionaSeguradora(this.SelectedSeguradora, status, null); base.ToggleSnackBar("EXTRATO BAIXADO COM SUCESSO", true); } else { this.SelectedExtrato.set_Status(3); await this._servico.Save(this.SelectedExtrato); if (this._servico.Sucesso) { this.SelectedStatusExtrato = 3; await this.SelecionaExtrato(this.SelectedExtrato); base.ToggleSnackBar("TODAS AS PARCELAS FORAM DESCONSIDERADAS PELO USUARIO", true); } } } } private async Task BaixarExtrato(List baixar) { List documentos; long num1; List vendedorParcelas; decimal? valorComissao; DateTime? recebimento; int? nullable; List list; StatusParcela? nullable1; DateTime? nullable2; bool valueOrDefault; string str; string str1; DateTime? nullable3; decimal comissao; SubTipo subTipo; int valueOrDefault1; DateTime? nullable4; string str2; DateTime? nullable5; int? nullable6; decimal? nullable7; decimal? nullable8; decimal? comissao1; bool ordem; ComissaoViewModel.u003cu003ec__DisplayClass225_0 variable; Parcela parcela1; bool flag = true; await this.CarregarImpostos(); this._apoliceServico.Sucesso = true; this._servico.Sucesso = true; this.Porcentagem = decimal.Zero; this.Indice = decimal.Zero; this.Total = baixar.Count; List detalheExtratos = baixar; IEnumerable hasValue = from x in detalheExtratos where x.get_Documento().HasValue select x; List nums = ( from x in hasValue select x.get_Documento().Value).ToList(); List detalheExtratos1 = baixar; IEnumerable detalheExtratos2 = detalheExtratos1.Where((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (x.get_Documento().HasValue) { return false; } return x.get_Parcela().HasValue; }); List list1 = ( from x in detalheExtratos2 select x.get_Parcela().Value).ToList(); if (nums.Count <= 0) { documentos = new List(); } else { documentos = await this._apoliceServico.BuscarApolicesPorId(nums); } List documentos1 = documentos; if (list1.Count > 0) { List documentos2 = documentos1; documentos = await this._apoliceServico.BuscarApolicesPorIdParcela(list1); documentos2.AddRange(documentos); documentos2 = null; } ParcelaServico parcelaServico = this._parcelaServico; List documentos3 = documentos1; List parcelas = await parcelaServico.BuscarTodasParcelas(( from x in documentos3 select x.get_Id()).ToList()); parcelas.ForEach((Parcela p) => p.set_Documento(documentos1.Find((Documento d) => d.get_Id() == p.get_Documento().get_Id()))); foreach (Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato in baixar) { long? documento = detalheExtrato.get_Documento(); if (!documento.HasValue) { documento = detalheExtrato.get_Parcela(); if (!documento.HasValue) { detalheExtrato.set_Status(new StatusParcela?(2)); await this._servico.Save(detalheExtrato); continue; } } decimal indice = this.Indice; this.Indice = indice++; this.Porcentagem = (this.Indice * new decimal(100)) / this.Total; bool flag1 = false; Documento documento1 = null; documento = detalheExtrato.get_Documento(); if (documento.HasValue) { documento = detalheExtrato.get_Documento(); num1 = (long)0; if (documento.GetValueOrDefault() > num1 & documento.HasValue) { documento1 = documentos1.Find((Documento d) => d.get_Id() == detalheExtrato.get_Documento().Value); } } if (!documento1.get_Excluido()) { if (documento1 != null && documento1.get_TipoRecebimento().GetValueOrDefault() == 1 && documento1.get_Comissao() == decimal.Zero) { documento = detalheExtrato.get_Parcela(); if (documento.HasValue) { documento = detalheExtrato.get_Parcela(); num1 = (long)999; if (documento.GetValueOrDefault() != num1 | !documento.HasValue) { Documento documento2 = documento1; if (documento2 != null) { ordem = documento2.get_Ordem() == 0; } else { ordem = false; } if (ordem) { continue; } } } } bool flag2 = true; documento = detalheExtrato.get_Documento(); if (documento.HasValue) { IEnumerable id = from p in parcelas where p.get_Documento().get_Id() == detalheExtrato.get_Documento().Value select p; list = ( from p in id orderby p.get_NumeroParcela() select p).ToList(); } else { list = null; } List parcelas1 = list; documento = detalheExtrato.get_Parcela(); if (!documento.HasValue) { if (parcelas1.Count <= 0) { VendedorServico vendedorServico = this._vendedorServico; documento = detalheExtrato.get_Documento(); vendedorParcelas = await vendedorServico.BuscaRepasse(documento.Value); } else { vendedorParcelas = await this._vendedorServico.BuscaRepasseParcela(parcelas1.First().get_Id()); } List vendedorParcelas1 = vendedorParcelas; Imposto imposto = this.CarregarImposto(documento1); valorComissao = detalheExtrato.get_ValorComissao(); decimal valueOrDefault2 = valorComissao.GetValueOrDefault() * imposto.get_Ir(); valorComissao = detalheExtrato.get_ValorComissao(); decimal num2 = valorComissao.GetValueOrDefault() * imposto.get_Iss(); valorComissao = detalheExtrato.get_ValorComissao(); decimal valueOrDefault3 = valorComissao.GetValueOrDefault() * imposto.get_Outros(); valorComissao = detalheExtrato.get_ValorComissao(); decimal num3 = valorComissao.GetValueOrDefault() * imposto.get_Desconto(); valorComissao = detalheExtrato.get_ValorComissao(); decimal valueOrDefault4 = valorComissao.GetValueOrDefault() - (((valueOrDefault2 + num2) + valueOrDefault3) + num3); if (documento1.get_TipoRecebimento().GetValueOrDefault() == 1) { recebimento = null; nullable3 = recebimento; } else { recebimento = detalheExtrato.get_Recebimento(); nullable3 = (!recebimento.HasValue ? this.SelectedExtrato.get_Data() : detalheExtrato.get_Recebimento()); } DateTime? nullable9 = nullable3; if (documento1.get_TipoRecebimento().GetValueOrDefault() == 1) { comissao = new decimal(100); } else { Parcela parcela2 = parcelas1.FirstOrDefault(); if (parcela2 != null) { comissao = parcela2.get_Comissao(); } else { valorComissao = detalheExtrato.get_Comissao(); comissao = valorComissao.GetValueOrDefault(new decimal(100)); } } decimal value = comissao; if (value == new decimal(100)) { valorComissao = detalheExtrato.get_Valor(); if (valorComissao.HasValue) { valorComissao = detalheExtrato.get_Comissao(); if (valorComissao.HasValue) { valorComissao = detalheExtrato.get_ValorComissao(); if (valorComissao.HasValue) { valorComissao = detalheExtrato.get_Valor(); decimal? comissao2 = detalheExtrato.get_Comissao(); indice = 100; if (comissao2.HasValue) { nullable7 = new decimal?(comissao2.GetValueOrDefault() / indice); } else { nullable7 = null; } decimal? nullable10 = nullable7; if (valorComissao.HasValue & nullable10.HasValue) { nullable8 = new decimal?(valorComissao.GetValueOrDefault() * nullable10.GetValueOrDefault()); } else { comissao2 = null; nullable8 = comissao2; } comissao2 = nullable8; decimal value1 = comissao2.Value; valorComissao = detalheExtrato.get_ValorComissao(); decimal value2 = valorComissao.Value; if (Math.Truncate(value1) == Math.Truncate(value2)) { Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato1 = detalheExtrato; if (detalheExtrato1 != null) { comissao1 = detalheExtrato1.get_Comissao(); } else { valorComissao = null; comissao1 = valorComissao; } valorComissao = comissao1; value = valorComissao.Value; } } } } } Parcela parcela3 = new Parcela(); parcela3.set_Documento(documento1); parcela3.set_Vencimento(Funcoes.GetNetworkTime().Date); parcela3.set_Comissao(value); if (documento1.get_TipoRecebimento().GetValueOrDefault() == 1) { subTipo = detalheExtrato.get_SubTipo().GetValueOrDefault(3); } else { subTipo = 1; } parcela3.set_SubTipo(subTipo); if (documento1.get_TipoRecebimento().GetValueOrDefault() == 1) { valueOrDefault1 = 999; } else { List parcelas2 = parcelas1; if (parcelas2 != null) { Parcela parcela4 = parcelas2.LastOrDefault(); if (parcela4 != null) { nullable6 = new int?(parcela4.get_NumeroParcela()); } else { nullable = null; nullable6 = nullable; } } else { nullable = null; nullable6 = nullable; } nullable = nullable6; valueOrDefault1 = nullable.GetValueOrDefault() + 1; } parcela3.set_NumeroParcela(valueOrDefault1); valorComissao = detalheExtrato.get_Valor(); parcela3.set_Valor(valorComissao.GetValueOrDefault()); valorComissao = detalheExtrato.get_Valor(); parcela3.set_ValorRealizado(valorComissao.GetValueOrDefault()); valorComissao = detalheExtrato.get_ValorComissao(); parcela3.set_ValorComissao(valorComissao.GetValueOrDefault()); parcela3.set_Irr(valueOrDefault2); parcela3.set_Iss(num2); parcela3.set_Outros(valueOrDefault3); parcela3.set_Desconto(num3); parcela3.set_ValorComDesconto(valueOrDefault4); parcela3.set_DataRecebimento(this.SelectedExtrato.get_Data()); recebimento = this.SelectedExtrato.get_DataCredito(); nullable4 = (recebimento.HasValue ? recebimento : this.SelectedExtrato.get_Data()); parcela3.set_DataCredito(nullable4); str2 = (documento1.get_TipoRecebimento().GetValueOrDefault() == 1 ? "" : detalheExtrato.get_Endosso()); parcela3.set_Fatura(str2); parcela3.set_Emissao(nullable9); parcela3.set_VigenciaIncial(nullable9); if (documento1.get_TipoRecebimento().GetValueOrDefault() == 1) { recebimento = null; nullable5 = recebimento; } else if (nullable9.HasValue) { DateTime dateTime = nullable9.GetValueOrDefault(); nullable5 = new DateTime?(dateTime.AddMonths(1)); } else { recebimento = null; nullable5 = recebimento; } parcela3.set_VigenciaFinal(nullable5); parcela3.set_Extrato(detalheExtrato.get_Extrato().get_Numero()); parcela3.set_DataCriacao(new DateTime?(DateTime.Now)); parcela1 = parcela3; if (documento1.get_Ordem() > 0) { VendedorServico vendedorServico1 = this._vendedorServico; Controle controle = await this._apoliceServico.BuscarControleAsync(documento1.get_Controle().get_Id()); VendedorServico vendedorServico2 = vendedorServico1; IList documentos4 = controle.get_Documentos(); vendedorServico1 = null; vendedorParcelas1 = await vendedorServico2.BuscaRepasse(documentos4.First((Documento d) => d.get_Ordem() == 0).get_Id()); List vendedorParcelas2 = vendedorParcelas1; vendedorParcelas1 = Funcoes.DistinctBy(vendedorParcelas2, (VendedorParcela v) => v.get_TipoVendedor()).ToList(); } if (vendedorParcelas1 != null) { List vendedorParcelas3 = vendedorParcelas1; ExtensionMethods.ForEach( from v in vendedorParcelas3 where v.get_Repasse() != null select v, (VendedorParcela v) => { v.set_Id((long)0); decimal num = Funcoes.CalculaRepasse(v.get_Repasse(), parcela1, false); if (v.get_Repasse().get_Forma().GetValueOrDefault() == 1) { v.set_DataPrePagamento(parcela1.get_DataRecebimento()); } BaseRepasse? @base = v.get_Repasse().get_Base(); if (@base.HasValue) { switch (@base.GetValueOrDefault()) { case 1: { v.set_DataPrePagamento((documento1.get_TipoRecebimento().GetValueOrDefault() == 2 ? parcela1.get_VigenciaIncial() : new DateTime?(documento1.get_Vigencia1()))); break; } case 2: { v.set_DataPrePagamento(parcela1.get_DataCriacao()); break; } case 3: { v.set_DataPrePagamento(new DateTime?(parcela1.get_Vencimento())); break; } case 4: { v.set_DataPrePagamento((documento1.get_TipoRecebimento().GetValueOrDefault() == 2 ? parcela1.get_Emissao() : documento1.get_Emissao())); break; } case 5: { v.set_DataPrePagamento((documento1.get_TipoRecebimento().GetValueOrDefault() == 2 ? parcela1.get_Emissao() : documento1.get_Remessa())); break; } } } v.set_ValorRepasse(new decimal?(num)); v.set_ValorTotal(new decimal?(num)); v.set_DataPagamento(null); }); } if (vendedorParcelas1 == null || vendedorParcelas1.Count == 0) { vendedorParcelas1 = new List() { ComissaoViewModel.PropriaCorretora() }; } if (parcela1.get_Documento().get_TipoRecebimento().GetValueOrDefault() == 1) { parcela1.set_Vendedores(new ObservableCollection(vendedorParcelas1)); parcela1.set_Extrato(detalheExtrato.get_Extrato().get_Numero()); Parcela parcela5 = await this._parcelaServico.Save(parcela1, this.Parcelas.ToList(), vendedorParcelas1, true); parcela1 = parcela5; if (this._parcelaServico.Sucesso) { detalheExtrato.set_Parcela(new long?(parcela1.get_Id())); flag1 = true; } else { variable = null; list1 = null; parcelas = null; return; } } } if (!flag1) { documento = detalheExtrato.get_Parcela(); if (!documento.HasValue) { continue; } parcela1 = parcelas.Find((Parcela p) => p.get_Id() == detalheExtrato.get_Parcela().Value); if (parcela1 == null) { continue; } detalheExtrato.set_Documento(new long?(parcela1.get_Documento().get_Id())); recebimento = parcela1.get_DataRecebimento(); if (!recebimento.HasValue) { List vendedorParcelas4 = await this._vendedorServico.BuscaRepasseParcela(parcela1.get_Id()); Imposto imposto1 = this.CarregarImposto(documento1); valorComissao = detalheExtrato.get_ValorComissao(); decimal num4 = valorComissao.GetValueOrDefault() * imposto1.get_Ir(); valorComissao = detalheExtrato.get_ValorComissao(); decimal valueOrDefault5 = valorComissao.GetValueOrDefault() * imposto1.get_Iss(); valorComissao = detalheExtrato.get_ValorComissao(); decimal num5 = valorComissao.GetValueOrDefault() * imposto1.get_Outros(); valorComissao = detalheExtrato.get_ValorComissao(); decimal valueOrDefault6 = valorComissao.GetValueOrDefault() * imposto1.get_Desconto(); valorComissao = detalheExtrato.get_ValorComissao(); decimal num6 = valorComissao.GetValueOrDefault() - (((num4 + valueOrDefault5) + num5) + valueOrDefault6); Parcela parcela6 = parcela1; valorComissao = detalheExtrato.get_Valor(); parcela6.set_ValorRealizado(valorComissao.GetValueOrDefault()); Parcela parcela7 = parcela1; valorComissao = detalheExtrato.get_ValorComissao(); parcela7.set_ValorComissao(valorComissao.GetValueOrDefault()); parcela1.set_Irr(num4); parcela1.set_Iss(valueOrDefault5); parcela1.set_Outros(num5); parcela1.set_Desconto(valueOrDefault6); parcela1.set_ValorComDesconto(num6); parcela1.set_DataRecebimento(this.SelectedExtrato.get_Data()); Parcela parcela8 = parcela1; recebimento = this.SelectedExtrato.get_DataCredito(); nullable2 = (recebimento.HasValue ? recebimento : this.SelectedExtrato.get_Data()); parcela8.set_DataCredito(nullable2); parcela1.set_Extrato(this.SelectedExtrato.get_Numero()); parcela1.set_Vendedores(new ObservableCollection(vendedorParcelas4)); documento1 = parcela1.get_Documento(); List list2 = parcelas1; if (list2 == null) { IEnumerable id1 = from p in parcelas where p.get_Documento().get_Id() == documento1.get_Id() select p; list2 = ( from p in id1 orderby p.get_NumeroParcela() select p).ToList(); } parcelas1 = list2; parcelas1.ForEach((Parcela p) => { if (p.get_Id() != parcela1.get_Id()) { return; } p.set_ValorRealizado(parcela1.get_ValorRealizado()); p.set_ValorComissao(parcela1.get_ValorComissao()); p.set_Irr(parcela1.get_Irr()); p.set_Iss(parcela1.get_Iss()); p.set_Outros(parcela1.get_Outros()); p.set_Desconto(parcela1.get_Desconto()); p.set_ValorComDesconto(parcela1.get_ValorComDesconto()); p.set_DataRecebimento(parcela1.get_DataRecebimento()); Parcela parcela = p; DateTime? dataCredito = parcela1.get_DataCredito(); parcela.set_DataCredito((dataCredito.HasValue ? dataCredito : parcela1.get_DataRecebimento())); p.set_Extrato(parcela1.get_Extrato()); }); bool flag3 = true; if (parcela1.get_SubTipo() == 1) { List parcelas3 = parcelas1; Parcela parcela9 = parcelas3.FirstOrDefault((Parcela p) => !p.get_DataRecebimento().HasValue); if (parcela9 != null && parcela9.get_NumeroParcela() < parcela1.get_NumeroParcela()) { detalheExtrato.set_Status(new StatusParcela?(7)); flag3 = false; flag2 = false; } } if (flag3) { Parcela parcela10 = parcela1; List parcelas4 = parcelas1; List list3 = parcela1.get_Vendedores().ToList(); valorComissao = parcela1.get_Documento().get_Controle().get_Seguradora().get_Tolerancia(); recebimento = await Funcoes.BaixarComissao(parcela10, parcelas4, list3, valorComissao.GetValueOrDefault(), true).get_DataRecebimento(); if (!recebimento.HasValue) { continue; } Documento documento3 = parcela1.get_Documento(); if (documento3 != null) { valueOrDefault = documento3.get_TipoRecebimento().GetValueOrDefault() == 1; } else { valueOrDefault = false; } str = (valueOrDefault ? string.Format("PARCELA {0} BAIXADA POR COMISSÃO AUTOMÁTICA, EXTRATO {1}", parcela1.get_NumeroParcela(), detalheExtrato.get_Extrato().get_Numero()) : string.Concat("FATURA ", parcela1.get_Fatura(), " BAIXADA POR COMISSÃO AUTOMÁTICA, EXTRATO ", detalheExtrato.get_Extrato().get_Numero())); string str3 = str; RegistroAcao registroAcao = new RegistroAcao(); registroAcao.set_Descricao(str3); registroAcao.set_EntidadeId(parcela1.get_Id()); registroAcao.set_Tela(new TipoTela?(35)); RegistroAcao registroAcao1 = registroAcao; if (documento1.get_Tipo() == 0) { str1 = string.Concat("APÓLICE: ", detalheExtrato.get_Apolice()); } else if (documento1.get_TipoRecebimento().GetValueOrDefault() == 2) { string[] apolice = new string[] { "APÓLICE: ", detalheExtrato.get_Apolice(), Environment.NewLine, "FATURA: ", detalheExtrato.get_Endosso() }; str1 = string.Concat(apolice); } else { string[] strArrays = new string[] { "APÓLICE: ", detalheExtrato.get_Apolice(), Environment.NewLine, "ENDOSSO: ", detalheExtrato.get_Endosso() }; str1 = string.Concat(strArrays); } string str4 = str1; object[] cliente = new object[] { detalheExtrato.get_Cliente(), Environment.NewLine, str4, Environment.NewLine, detalheExtrato.get_NumeroParcela(), detalheExtrato.get_Valor(), detalheExtrato.get_Comissao(), detalheExtrato.get_ValorComissao() }; string str5 = string.Format("CLIENTE: {0}{1}{2}{3}PARCELA: {4}, VALOR: {5:c2} COMISSÃO: {6:N2}% VALOR COMISSÃO: {7:c2}", cliente); this._parcelaServico.SalvarAcao(registroAcao1, str5); } } else { detalheExtrato.set_Status(new StatusParcela?(5)); await this._servico.Save(detalheExtrato); continue; } } if (detalheExtrato.get_Corrigir()) { if (!await this._apoliceServico.AtualizarNumero(documento1.get_Id(), detalheExtrato.get_Apolice(), detalheExtrato.get_Endosso(), documento1.get_Tipo())) { flag = false; } } StatusParcela? status = detalheExtrato.get_Status(); if (status.HasValue) { StatusParcela statusParcela = status.GetValueOrDefault(); if (statusParcela == 4) { detalheExtrato.set_Status(new StatusParcela?(10)); goto Label1; } else { if (statusParcela != 14) { goto Label2; } detalheExtrato.set_Status(new StatusParcela?(13)); goto Label1; } } Label2: Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato2 = detalheExtrato; nullable1 = (flag2 ? new StatusParcela?(1) : detalheExtrato.get_Status()); detalheExtrato2.set_Status(nullable1); Label1: await this._servico.Save(detalheExtrato); if (this._servico.Sucesso) { parcelas1 = null; } else { variable = null; list1 = null; parcelas = null; return; } } else { detalheExtrato.set_Status(new StatusParcela?(2)); await this._servico.Save(detalheExtrato); } } this.SelectedExtrato.set_Status(3); await this._servico.Save(this.SelectedExtrato); if (!flag) { await base.ShowMessage("OCORREU UM ERRO AO ATUALIZAR O NÚMERO DA APÓLICE/ENDOSSO DOS DOCUMENTOS BAIXADOS.", "OK", "", false); } variable = null; list1 = null; parcelas = null; } public async Task BaixarTodosExtratos() { Func func1 = null; if (this.Extratos != null && this.Extratos.Count != 0) { StatusExtrato status = this.Extratos[0].get_Status(); this.PorcentagemExtrato = decimal.Zero; this.IndiceTotal = decimal.Zero; this.TotalExtratos = this.Extratos.Count; List statusParcelas = new List() { 9, 14, 16, 4, 17, 15, 18 }; List statusParcelas1 = statusParcelas; await Task.Run(async () => { ObservableCollection extratos = this.Extratos; Func u003cu003e9_2281 = ComissaoViewModel.u003cu003ec.u003cu003e9__228_1; if (u003cu003e9_2281 == null) { u003cu003e9_2281 = (Extrato x) => x.get_Data(); ComissaoViewModel.u003cu003ec.u003cu003e9__228_1 = u003cu003e9_2281; } foreach (Extrato extrato in extratos.OrderBy(u003cu003e9_2281)) { decimal indiceTotal = this.IndiceTotal; this.IndiceTotal = indiceTotal++; this.PorcentagemExtrato = (this.IndiceTotal * new decimal(100)) / this.TotalExtratos; ObservableCollection observableCollection = await this.CarregarDetalhes(extrato); Func u003cu003e9_2 = func1; if (u003cu003e9_2 == null) { Func hasValue = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas1.Contains(x.get_Status().Value); }; Func func = hasValue; func1 = hasValue; u003cu003e9_2 = func; } List list = observableCollection.Where(u003cu003e9_2).ToList(); this.SelectedExtrato = extrato; ComissaoViewModel u003cu003e4_this = this; List detalheExtratos = list; Func u003cu003e9_2283 = ComissaoViewModel.u003cu003ec.u003cu003e9__228_3; if (u003cu003e9_2283 == null) { u003cu003e9_2283 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Cliente(); ComissaoViewModel.u003cu003ec.u003cu003e9__228_3 = u003cu003e9_2283; } IOrderedEnumerable detalheExtratos1 = detalheExtratos.OrderBy(u003cu003e9_2283); Func u003cu003e9_2284 = ComissaoViewModel.u003cu003ec.u003cu003e9__228_4; if (u003cu003e9_2284 == null) { u003cu003e9_2284 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Apolice(); ComissaoViewModel.u003cu003ec.u003cu003e9__228_4 = u003cu003e9_2284; } IOrderedEnumerable detalheExtratos2 = detalheExtratos1.ThenBy(u003cu003e9_2284); Func u003cu003e9_2285 = ComissaoViewModel.u003cu003ec.u003cu003e9__228_5; if (u003cu003e9_2285 == null) { u003cu003e9_2285 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Endosso(); ComissaoViewModel.u003cu003ec.u003cu003e9__228_5 = u003cu003e9_2285; } IOrderedEnumerable detalheExtratos3 = detalheExtratos2.ThenBy(u003cu003e9_2285); Func u003cu003e9_2286 = ComissaoViewModel.u003cu003ec.u003cu003e9__228_6; if (u003cu003e9_2286 == null) { u003cu003e9_2286 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_NumeroParcela(); ComissaoViewModel.u003cu003ec.u003cu003e9__228_6 = u003cu003e9_2286; } await u003cu003e4_this.BaixarExtrato(detalheExtratos3.ThenBy(u003cu003e9_2286).ToList()); } }); this.SelecionaSeguradora(this.SelectedSeguradora, status, null); base.ToggleSnackBar("EXTRATOS BAIXADOS COM SUCESSO", true); } } public async Task BuscarCriticado(Gestor.Model.Domain.Seguros.DetalheExtrato detalhe) { long? parcela; Parcela parcela1; if (detalhe != null) { this.SelectedDetalhe = this.DetalheExtratoFiltrados.First((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Id() == detalhe.get_Id()); if (this.SelectedDetalhe.get_Parcela().HasValue || this.SelectedDetalhe.get_Documento().HasValue) { this.Buscando = true; ParcelaServico parcelaServico = new ParcelaServico(); parcela1 = null; Documento documento = null; if (this.SelectedDetalhe.get_Parcela().HasValue) { parcela = this.SelectedDetalhe.get_Parcela(); parcela1 = await parcelaServico.BuscarParcela(parcela.Value); if (parcela1 != null) { detalhe.set_Documento(new long?(parcela1.get_Documento().get_Id())); documento = parcela1.get_Documento(); } } if (this.SelectedDetalhe.get_Documento().HasValue && !this.SelectedDetalhe.get_Parcela().HasValue) { ApoliceServico apoliceServico = this._apoliceServico; parcela = this.SelectedDetalhe.get_Documento(); Documento documento1 = await apoliceServico.BuscarApoliceAsync(parcela.Value, false, false); documento = documento1; } if (documento != null) { this.SelectedCliente = documento.get_Controle().get_Cliente(); await this.SelecionaCliente(documento.get_Controle().get_Cliente()); this.SelectedDocumento = this.Apolices.FirstOrDefault((Documento x) => x.get_Id() == documento.get_Id()); await this.SelecionaDocumento(documento); this.SelecionaParcela(parcela1); this.Buscando = false; } else { this.Buscando = false; } } else { this.TodasApolices = null; this.Apolices = null; this.Parcelas = null; } } parcela1 = null; } public async Task CarregaDetalhes(Extrato extrato) { if (extrato != null && extrato.get_Id() != 0) { this._carregadoDetalhes = true; this.AllSelected = false; this.DetalheExtrato = await this._servico.BuscarDetalhes(extrato.get_Id()); this.DetalheExtratoFiltrados = this.DetalheExtrato; this.SelecionaNormal(); this._carregadoDetalhes = false; List statusParcelas = new List() { 2, 3 }; List statusParcelas1 = new List() { 1, 13, 10 }; List statusParcelas2 = new List() { 16, 9, 14, 4, 17, 18 }; List statusParcelas3 = statusParcelas2; List statusParcelas4 = new List() { 1, 13, 10, 5, 12, 6, 8 }; List statusParcelas5 = statusParcelas4; this.DesfazerVisibility = this.DetalheExtrato.Any((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas1.Contains(x.get_Status().Value); }); this.DesconsiderarVisibility = this.DetalheExtrato.Any((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas.Contains(x.get_Status().Value); }); this.BaixarVisibility = this.DetalheExtrato.Any((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas3.Contains(x.get_Status().Value); }); if (this.SelectedExtrato != null) { this.FinalizarVisibility = this.DetalheExtrato.All((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue || !statusParcelas5.Contains(x.get_Status().Value)) { return false; } if (this.SelectedExtrato.get_Status() == 1) { return true; } return !this.SelectedExtrato.get_Completo(); }); } } } private async Task> CarregarDetalhes(Extrato extrato) { return await this._servico.BuscarDetalhes(extrato.get_Id()); } public Imposto CarregarImposto(Documento documento) { return this.Impostos.FirstOrDefault((Imposto x) => { if (x.get_Seguradora() == null || x.get_Seguradora().get_Id() != documento.get_Controle().get_Seguradora().get_Id() || x.get_Ramo() == null) { return false; } return x.get_Ramo().get_Id() == documento.get_Controle().get_Ramo().get_Id(); }) ?? this.Impostos.FirstOrDefault((Imposto x) => { if (x.get_Seguradora() == null || x.get_Seguradora().get_Id() != documento.get_Controle().get_Seguradora().get_Id()) { return false; } return x.get_Ramo() == null; }) ?? this.Impostos.FirstOrDefault((Imposto x) => { if (x.get_Seguradora() != null || x.get_Ramo() == null) { return false; } return x.get_Ramo().get_Id() == documento.get_Controle().get_Ramo().get_Id(); }) ?? this.Impostos.FirstOrDefault((Imposto x) => { if (x.get_Seguradora() != null) { return false; } return x.get_Ramo() == null; }) ?? new Imposto(); } private async Task CarregarImpostos() { List impostos = await (new ImpostoServico()).Buscar(new bool?(true)); ComissaoViewModel comissaoViewModel = this; List impostos1 = impostos; if (impostos1 == null) { impostos1 = new List(); } comissaoViewModel.Impostos = impostos1; } public async Task Criticar(Gestor.Model.Domain.Seguros.DetalheExtrato detalhe, bool critica) { long? nullable; StatusParcela statusParcela; long? nullable1; string str; object obj; bool subTipo; StatusParcela statusParcela1; ComissaoViewModel.u003cu003ec__DisplayClass215_0 variable; List detalheExtratos; if (detalhe != null && this.SelectedDocumento != null | !critica) { base.Loading(true); this.IsVisibleDetalhes = Visibility.Collapsed; detalheExtratos = new List(); if (critica) { List configuracoes = Recursos.Configuracoes; bool flag = configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 12); SubTipo? subTipo1 = detalhe.get_SubTipo(); if (!subTipo1.HasValue || subTipo1.GetValueOrDefault() > 1) { Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato = detalhe; if (this.SelectedParcela == null || !flag && this.SelectedParcela.get_SubTipo() == 1) { statusParcela = 17; } else { statusParcela = (this.SelectedParcela.get_DataRecebimento().HasValue ? 5 : 14); } detalheExtrato.set_Status(new StatusParcela?(statusParcela)); detalhe.set_Documento(new long?(this.SelectedDocumento.get_Id())); Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato1 = detalhe; if (this.SelectedParcela != null && this.SelectedParcela.get_Id() != 0) { if (!flag) { Parcela selectedParcela = this.SelectedParcela; if (selectedParcela != null) { subTipo = selectedParcela.get_SubTipo() == 1; } else { subTipo = false; } if (subTipo) { goto Label1; } } nullable1 = new long?(this.SelectedParcela.get_Id()); goto Label0; } Label1: nullable = null; nullable1 = nullable; Label0: detalheExtrato1.set_Parcela(nullable1); } else { ObservableCollection parcelas = this.Parcelas; Parcela parcela1 = parcelas.FirstOrDefault((Parcela x) => !x.get_DataRecebimento().HasValue); Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato2 = detalhe; if (parcela1 == null || parcela1.get_NumeroParcela() >= this.SelectedParcela.get_NumeroParcela()) { statusParcela1 = (this.SelectedParcela.get_DataRecebimento().HasValue ? 5 : 14); } else { statusParcela1 = 7; } detalheExtrato2.set_Status(new StatusParcela?(statusParcela1)); detalhe.set_Documento(new long?(this.SelectedDocumento.get_Id())); detalhe.set_Parcela(new long?(this.SelectedParcela.get_Id())); IEnumerable detalheExtratos1 = this.DetalheExtrato.Where((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!(x.get_Cliente() == this.detalhe.get_Cliente()) || !(x.get_Apolice() == this.detalhe.get_Apolice()) || !(x.get_NumeroParcela() != this.detalhe.get_NumeroParcela()) || x.get_SubTipo().GetValueOrDefault() != 1) { return false; } if (x.get_Status().GetValueOrDefault() == 2) { return true; } return x.get_Status().GetValueOrDefault() == 3; }); detalheExtratos = ( from x in detalheExtratos1 orderby x.get_NumeroParcela() select x).ToList(); bool count = detalheExtratos.Count > 0; if (count) { count = await base.ShowMessage("DESEJA CRITICAR AUTOMATICAMENTE AS PRÓXIMAS PARCELAS DESTE DOCUMENTO?", "SIM", "NÃO", false); } if (!count) { detalheExtratos = null; } else { detalheExtratos.ForEach((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { int num; if (!int.TryParse(x.get_NumeroParcela(), out num)) { return; } Parcela parcela = this.Parcelas.FirstOrDefault((Parcela p) => p.get_NumeroParcela() == int.Parse(x.get_NumeroParcela())); if (parcela == null) { return; } x.set_Status(new StatusParcela?((parcela1 == null || parcela1.get_NumeroParcela() >= parcela.get_NumeroParcela() ? (parcela.get_DataRecebimento().HasValue ? 5 : 14) : 7))); x.set_Documento(new long?(this.SelectedDocumento.get_Id())); x.set_Parcela(new long?(parcela.get_Id())); }); } } } else { detalhe.set_Status(new StatusParcela?(6)); nullable = null; detalhe.set_Documento(nullable); nullable = null; detalhe.set_Parcela(nullable); } await this._servico.Save(detalhe); if (this._servico.Sucesso) { if (detalheExtratos != null && detalheExtratos.Count > 0) { foreach (Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato3 in detalheExtratos) { await this._servico.Save(detalheExtrato3); if (this._servico.Sucesso) { continue; } variable = null; detalheExtratos = null; return; } } await this.CarregaDetalhes(this.SelectedExtrato); this.IsVisibleDetalhes = Visibility.Visible; base.Loading(false); base.ToggleSnackBar("CRÍTICA REALIZADA COM SUCESSO", true); str = (this.SelectedParcela == null ? "ESPECIAL" : this.SelectedParcela.get_NumeroParcela().ToString()); string str1 = str; ComissaoViewModel comissaoViewModel = this; object[] numeroParcela = new object[] { (critica ? "CRITICOU" : "DESCONSIDEROU"), detalhe.get_NumeroParcela(), detalhe.get_Extrato().get_Numero(), detalhe.get_Extrato().get_Id() }; string str2 = string.Format("{0} PARCELA NÚMERO \"{1}\" DO EXTRATO NÚMERO \n{2}\n, ID {3}", numeroParcela); long id = this.SelectedExtrato.get_Id(); TipoTela? nullable2 = new TipoTela?(35); obj = (critica ? string.Format("CRITICOU A PARCELA \"{0}\" DO DOCUMENTO DE ID \n{1}\n", str1, this.SelectedDocumento.get_Id()) : ""); comissaoViewModel.RegistrarAcao(str2, id, nullable2, obj); } else { base.Loading(false); } } variable = null; detalheExtratos = null; } public async Task CriticarTodos(long id) { ObservableCollection observableCollection = await this._servico.BuscarDetalhes(id); foreach (Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato in observableCollection) { if (detalheExtrato.get_Status().GetValueOrDefault() != 2 && detalheExtrato.get_Status().GetValueOrDefault() != 3) { continue; } detalheExtrato.set_Status(new StatusParcela?(6)); await this._servico.Save(detalheExtrato); if (this._servico.Sucesso) { continue; } observableCollection = null; return; } ObservableCollection observableCollection1 = observableCollection; if (observableCollection1.All((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Status().GetValueOrDefault() == 6)) { this.SelectedExtrato.set_Status(3); this.SelectedStatusExtrato = 3; await this.SelecionaExtrato(this.SelectedExtrato); } await this.CarregaDetalhes(this.SelectedExtrato); base.ToggleSnackBar("CRÍTICA REALIZADA COM SUCESSO", true); base.RegistrarAcao(string.Format("DESCONSIDEROU TODAS AS PARCELAS COM O STATUS DE DOCUMENTO NÃO ENCONTRADO OU PARCELA NÃO ENCONTRADA DO EXTRATO DE ID \n{0}\n", id), id, new TipoTela?(35), null); observableCollection = null; } public async Task DesconsiderarSelecionadas() { if (this.DetalheExtrato != null && this.DetalheExtrato.Count != 0) { List statusParcelas = new List() { 1, 5, 8, 10, 12, 13, 21, 8, 6 }; List statusParcelas1 = statusParcelas; ObservableCollection detalheExtrato = this.DetalheExtrato; IEnumerable selecionado = from parcelas in detalheExtrato where parcelas.get_Selecionado() select parcelas; if (selecionado.Any((Gestor.Model.Domain.Seguros.DetalheExtrato parcelas) => statusParcelas1.Any((StatusParcela status) => { StatusParcela? nullable = parcelas.get_Status(); return status == nullable.GetValueOrDefault() & nullable.HasValue; }))) { await base.ShowMessage("HÁ PARCELAS SELECIONADAS QUE JÁ ESTÃO BAIXADAS OU JÁ DESCONSIDERADAS", "OK", "", false); } else { foreach (Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato1 in selecionado) { detalheExtrato1.set_Status(new StatusParcela?(6)); await this._servico.Save(detalheExtrato1); if (this._servico.Sucesso) { continue; } return; } await this.CarregaDetalhes(this.SelectedExtrato); } } } public async Task DesfazerExtrato() { ObservableCollection observableCollection; if (this.DetalheExtrato != null && this.DetalheExtrato.Count != 0) { List statusParcelas = new List() { 1, 10, 12, 13 }; List list = this.DetalheExtrato.Where((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas.Contains(x.get_Status().Value); }).ToList(); if (list.Count != 0) { this.Porcentagem = decimal.Zero; this.Indice = decimal.Zero; this.Total = list.Count; List detalheExtratos4 = new List(); await Task.Run(async () => { List detalheExtratos = list; Func u003cu003e9_2352 = ComissaoViewModel.u003cu003ec.u003cu003e9__235_2; if (u003cu003e9_2352 == null) { u003cu003e9_2352 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Cliente(); ComissaoViewModel.u003cu003ec.u003cu003e9__235_2 = u003cu003e9_2352; } IOrderedEnumerable detalheExtratos1 = detalheExtratos.OrderBy(u003cu003e9_2352); Func u003cu003e9_2353 = ComissaoViewModel.u003cu003ec.u003cu003e9__235_3; if (u003cu003e9_2353 == null) { u003cu003e9_2353 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Apolice(); ComissaoViewModel.u003cu003ec.u003cu003e9__235_3 = u003cu003e9_2353; } IOrderedEnumerable detalheExtratos2 = detalheExtratos1.ThenBy(u003cu003e9_2353); Func u003cu003e9_2354 = ComissaoViewModel.u003cu003ec.u003cu003e9__235_4; if (u003cu003e9_2354 == null) { u003cu003e9_2354 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Endosso(); ComissaoViewModel.u003cu003ec.u003cu003e9__235_4 = u003cu003e9_2354; } IOrderedEnumerable detalheExtratos3 = detalheExtratos2.ThenBy(u003cu003e9_2354); Func u003cu003e9_2355 = ComissaoViewModel.u003cu003ec.u003cu003e9__235_5; if (u003cu003e9_2355 == null) { u003cu003e9_2355 = (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_NumeroParcela(); ComissaoViewModel.u003cu003ec.u003cu003e9__235_5 = u003cu003e9_2355; } foreach (Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato in detalheExtratos3.ThenByDescending(u003cu003e9_2355)) { decimal indice = this.Indice; this.Indice = indice++; this.Porcentagem = (this.Indice * new decimal(100)) / this.Total; if (!await this.DesfazerParcela(detalheExtrato)) { detalheExtratos4.Add(detalheExtrato); } } }); this.SelectedExtrato.set_Status(1); await this._servico.Save(this.SelectedExtrato); if (this._servico.Sucesso) { observableCollection = await this.CarregarDetalhes(this.SelectedExtrato); if (detalheExtratos4.Count <= 0) { base.ToggleSnackBar("EXTRATO DESFEITO COM SUCESSO", true); } else { await base.ShowDetalheExtrato(detalheExtratos4); } base.RegistrarAcao(string.Format("DESFEZ EXTRATO DE ID \n{0}\n", this.SelectedExtrato.get_Id()), this.SelectedExtrato.get_Id(), new TipoTela?(35), null); bool flag = !observableCollection.Any((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas.Contains(x.get_Status().Value); }); if (flag) { flag = await base.ShowMessage("DESEJA EXCLUIR O EXTRATO DESFEITO?", "SIM", "NÃO", false); } if (flag) { await this.ExcluirExtrato(); this.SelectedExtrato = null; } this.Carregando = true; this.SelectedStatusExtrato = 1; this.Carregando = false; this.SelecionaSeguradora(this.SelectedSeguradora, this.SelectedStatusExtrato, this.SelectedExtrato); } } else { await base.ShowMessage("NÃO HÁ PARCELAS PARA SEREM DESFEITAS NO EXTRATO", "OK", "", false); } } observableCollection = null; } public async Task DesfazerParcela(Gestor.Model.Domain.Seguros.DetalheExtrato detalhe) { bool flag; long? parcela; bool hasValue; bool flag1; StatusParcela statusParcela; Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato = detalhe; if (detalheExtrato != null) { parcela = detalheExtrato.get_Parcela(); hasValue = !parcela.HasValue; } else { hasValue = true; } if (!hasValue) { try { ParcelaServico parcelaServico = this._parcelaServico; parcela = detalhe.get_Parcela(); Parcela parcela1 = await parcelaServico.BuscarParcela(parcela.Value); if (parcela1 != null) { detalhe.set_Documento(new long?(parcela1.get_Documento().get_Id())); parcela1.set_Extrato(null); ParcelaServico parcelaServico1 = this._parcelaServico; parcela = detalhe.get_Documento(); List parcelas = await parcelaServico1.BuscarParcelas(parcela.Value); List parcelas1 = parcelas; IOrderedEnumerable numeroParcela = from p in parcelas1 orderby p.get_NumeroParcela() descending select p; Parcela parcela2 = numeroParcela.FirstOrDefault((Parcela p) => { if (!p.get_DataRecebimento().HasValue) { return false; } return p.get_SubTipo() == 1; }); bool flag2 = await this._parcelaServico.TemPagamento(parcela1.get_Id()); if (parcela1.get_Documento().get_TipoRecebimento().GetValueOrDefault() != 1) { List configuracoes = Recursos.Configuracoes; if (configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 28)) { goto Label0; } } if (flag2) { flag1 = true; } else { flag1 = (parcela2 == null ? false : parcela2.get_NumeroParcela() > parcela1.get_NumeroParcela()); } flag2 = flag1; Label0: if (!flag2 || parcela1.get_Documento().get_Excluido()) { VendedorServico vendedorServico = this._vendedorServico; parcela = detalhe.get_Documento(); List vendedorParcelas = await vendedorServico.BuscaRepasse(parcela.Value); await Funcoes.ExcluirBaixa(parcela1, vendedorParcelas, parcelas); Parcela parcela3 = parcelas.FirstOrDefault((Parcela x) => x.get_NumeroParcela() == int.Parse(detalhe.get_NumeroParcela()) - 1); Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtrato1 = detalhe; if (parcela3 != null && !parcela3.get_DataRecebimento().HasValue) { statusParcela = 7; } else if (detalhe.get_Status().GetValueOrDefault() == 13) { statusParcela = 14; } else { decimal? comissao = detalhe.get_Comissao(); if (comissao.HasValue) { decimal num = parcela1.get_Documento().get_Comissao(); comissao = detalhe.get_Comissao(); if ((num == comissao.GetValueOrDefault()) & comissao.HasValue) { goto Label2; } statusParcela = 4; goto Label1; } Label2: statusParcela = 9; } Label1: detalheExtrato1.set_Status(new StatusParcela?(statusParcela)); await this._servico.Save(detalhe); flag = true; } else { flag = false; } } else { parcela = null; detalhe.set_Documento(parcela); parcela = null; detalhe.set_Parcela(parcela); detalhe.set_Status(new StatusParcela?(2)); await this._servico.Save(detalhe); flag = false; } } catch (Exception exception1) { Exception exception = exception1; (new BaseServico()).Registrar(exception, 292, 3, detalhe, true); flag = false; } } else { flag = false; } return flag; } public async Task ExcluirExtrato() { if (this.SelectedExtrato != null) { List statusParcelas = new List() { 1, 10, 13 }; try { if (this.DetalheExtrato.Any((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (!x.get_Status().HasValue) { return false; } return statusParcelas.Contains(x.get_Status().Value); })) { await base.ShowMessage("O EXTRATO NÃO PODE SER EXCLUÍDO POIS FOI UTILIZADO PARA BAIXAR PARCELAS, DESFAÇA O EXTRATO ANTES DE EXCLUÍ-LO", "OK", "", false); return; } else if (await this._servico.Delete(this.SelectedExtrato)) { base.RegistrarAcao(string.Format("EXCLUIU EXTRATO DE ID \n{0}\n", this.SelectedExtrato.get_Id()), this.SelectedExtrato.get_Id(), new TipoTela?(35), null); this.SelectedExtrato = null; this.SelecionaSeguradora(this.SelectedSeguradora, 1, null); base.ToggleSnackBar("EXTRATO EXCLUÍDO COM SUCESSO", true); } else { return; } } catch (Exception exception) { } } } public void ExcluirFiltro(string filtro) { this.FiltroPersonalizado.Remove(filtro); this.FiltrarExtrato(); } private List Filtrar() { List list = this.Extratos.ToList(); this.FiltroPersonalizado.ToList().ForEach((string f) => { IEnumerable extratos = list.Where((Extrato x) => { if (ValidationHelper.RemoveDiacritics(x.get_Seguradora().get_Nome()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(f)) || ValidationHelper.RemoveDiacritics(x.get_Numero()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(f)) || x.get_Data().HasValue && x.get_Data().ToString().Contains(f) || x.get_Bruto().HasValue && x.get_Bruto().ToString().Contains(f) || x.get_Liquido().HasValue && x.get_Liquido().ToString().Contains(f)) { return true; } if (!x.get_DataCredito().HasValue) { return false; } return x.get_DataCredito().ToString().Contains(f); }); Func u003cu003e9_2542 = ComissaoViewModel.u003cu003ec.u003cu003e9__254_2; if (u003cu003e9_2542 == null) { u003cu003e9_2542 = (Extrato x) => x.get_Numero(); ComissaoViewModel.u003cu003ec.u003cu003e9__254_2 = u003cu003e9_2542; } IOrderedEnumerable extratos1 = extratos.OrderBy(u003cu003e9_2542); Func u003cu003e9_2543 = ComissaoViewModel.u003cu003ec.u003cu003e9__254_3; if (u003cu003e9_2543 == null) { u003cu003e9_2543 = (Extrato x) => x.get_DataCredito(); ComissaoViewModel.u003cu003ec.u003cu003e9__254_3 = u003cu003e9_2543; } list = extratos1.ThenByDescending(u003cu003e9_2543).ToList(); }); return list; } internal async Task> FiltrarApolices(string value) { List documentos = await Task.Run>(() => this.FiltrarDocumento(value)); return documentos; } internal async Task> FiltrarDetalhe(string value) { List detalheExtratos = await Task.Run>(() => this.FiltrarDetalheExtrato(value)); return detalheExtratos; } public List FiltrarDetalheExtrato(string filter) { if (this.DetalheExtrato == null) { return null; } this.DetalheExtratoFiltrados = (string.IsNullOrWhiteSpace(filter) ? this.DetalheExtrato : new ObservableCollection(this.DetalheExtrato.Where((Gestor.Model.Domain.Seguros.DetalheExtrato x) => { if (ValidationHelper.RemoveDiacritics(x.get_Cliente()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) || x.get_Apolice().Contains(filter)) { return true; } return x.get_Endosso().Contains(filter); }).OrderBy((Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.get_Cliente()))); return this.DetalheExtratoFiltrados.ToList(); } public List FiltrarDetalheExtrato(long id) { this.DetalheExtratoFiltrados = new ObservableCollection( from x in this.DetalheExtrato where x.get_Id() == id select x); return this.DetalheExtratoFiltrados.ToList(); } public List FiltrarDocumento(string filter) { this.Apolices = (string.IsNullOrWhiteSpace(filter) ? this.TodasApolices : new ObservableCollection(this.TodasApolices.Where((Documento x) => { if (x.get_Apolice() != null && x.get_Apolice().ToUpper().Contains(filter.ToUpper()) || x.get_Endosso() != null && x.get_Endosso().ToUpper().Contains(filter.ToUpper()) || x.get_Vigencia1().ToString("d").Contains(filter)) { return true; } if (!x.get_Vigencia2().HasValue) { return false; } return x.get_Vigencia2().Value.ToString("d").Contains(filter); }))); this.SelectedDocumento = null; this.SelectedParcela = null; ObservableCollection apolices = this.Apolices; if (apolices != null) { return apolices.ToList(); } return null; } public void FiltrarExtrato() { bool count; this.ExtratosFiltrados = new ObservableCollection(this.Filtrar()); this.SelectedExtrato = this.ExtratosFiltrados.FirstOrDefault(); ObservableCollection extratosFiltrados = this.ExtratosFiltrados; if (extratosFiltrados != null) { count = extratosFiltrados.Count > 0; } else { count = false; } this.IsExpanded = count; } public async Task FinalizarExtrato() { if (this.DetalheExtrato != null && this.DetalheExtrato.Count != 0) { StatusExtrato selectedStatusExtrato = this.SelectedStatusExtrato; this.SelectedExtrato.set_Status(3); Extrato extrato = await this._servico.Save(this.SelectedExtrato); if (this._servico.Sucesso) { this.SelectedExtrato = null; this.SelecionaSeguradora(this.SelectedSeguradora, selectedStatusExtrato, null); base.ToggleSnackBar("EXTRATO FINALIZADO COM SUCESSO", true); base.RegistrarAcao(string.Format("FINALIZOU EXTRATO DE ID \n{0}\n", extrato.get_Id()), extrato.get_Id(), new TipoTela?(35), null); } } } public async Task GerarHtml() { string nome; ExtratoComissao extratoComissao = new ExtratoComissao(); Usuario usuario = Auxiliar.get_Usuarios().FirstOrDefault((Usuario x) => x.get_Id() == this.SelectedExtrato.get_IdUsuario()); if (usuario != null) { nome = usuario.get_Nome(); } else { nome = null; } extratoComissao.set_Usuario(nome); extratoComissao.set_Seguradora(this.SelectedExtrato.get_Seguradora().get_Nome()); extratoComissao.set_DetalhesExtrato(new ObservableCollection()); ObservableCollection observableCollection = new ObservableCollection(); InformacoesExtrato informacoesExtrato = new InformacoesExtrato(); informacoesExtrato.set_NumeroExtrato(this.SelectedExtrato.get_Numero()); informacoesExtrato.set_DataExtrato(this.SelectedExtrato.get_Data()); decimal? bruto = this.SelectedExtrato.get_Bruto(); informacoesExtrato.set_Bruto(bruto.GetValueOrDefault()); bruto = this.SelectedExtrato.get_Liquido(); informacoesExtrato.set_Liquido(bruto.GetValueOrDefault()); bruto = this.SelectedExtrato.get_Ir(); informacoesExtrato.set_Ir(bruto.GetValueOrDefault()); bruto = this.SelectedExtrato.get_Iss(); informacoesExtrato.set_Iss(bruto.GetValueOrDefault()); bruto = this.SelectedExtrato.get_Outro(); informacoesExtrato.set_Outros(bruto.GetValueOrDefault()); informacoesExtrato.set_Quantidade(this.Quantidade); informacoesExtrato.set_TotalBaixado(this.TotalBaixado); informacoesExtrato.set_TotalPendente(this.TotalPendente); observableCollection.Add(informacoesExtrato); extratoComissao.set_InformacoesExtrato(observableCollection); ExtratoComissao extratoComissao1 = extratoComissao; foreach (Gestor.Model.Domain.Seguros.DetalheExtrato detalheExtratoFiltrado in this.DetalheExtratoFiltrados) { DetalhesExtrato detalhesExtrato = new DetalhesExtrato(); detalhesExtrato.set_Cliente(detalheExtratoFiltrado.get_Cliente()); detalhesExtrato.set_Apolice(detalheExtratoFiltrado.get_Apolice()); detalhesExtrato.set_Endosso(detalheExtratoFiltrado.get_Endosso()); detalhesExtrato.set_Parcela(detalheExtratoFiltrado.get_NumeroParcela()); detalhesExtrato.set_Pagto(detalheExtratoFiltrado.get_Valor()); detalhesExtrato.set_Comissao(detalheExtratoFiltrado.get_Comissao()); detalhesExtrato.set_ValorComissao(detalheExtratoFiltrado.get_ValorComissao()); detalhesExtrato.set_Status(ValidationHelper.GetDescription(detalheExtratoFiltrado.get_Status())); extratoComissao1.get_DetalhesExtrato().Add(detalhesExtrato); } string str = await Funcoes.GenerateTable(extratoComissao1.get_InformacoesExtrato().ToList(), new List(), false, false, "", null); string str1 = await Funcoes.GenerateTable(extratoComissao1.get_DetalhesExtrato().ToList(), new List(), false, false, "", null); string str2 = string.Concat(str, str1); str = null; string str3 = Funcoes.CreateCard(string.Concat("SEGURADORA: ", extratoComissao1.get_Seguradora(), "
USUÁRIO IMPORTAÇÃO: ", extratoComissao1.get_Usuario()), str2, false); TipoRelatorio tipoRelatorio = new TipoRelatorio(); tipoRelatorio.set_Nome("EXTRATO DE COMISSÃO"); string str4 = str3; if (str4 == null) { str4 = ""; } string str5 = Funcoes.ExportarHtml(tipoRelatorio, str4, "70", "landscape", false, ""); extratoComissao1 = null; return str5; } private static VendedorParcela PropriaCorretora() { Vendedor vendedor = Recursos.Vendedores.FirstOrDefault((Vendedor x) => { if (x.get_IdEmpresa() != Recursos.Empresa.get_Id()) { return false; } return x.get_Corretora(); }); VendedorParcela vendedorParcela = new VendedorParcela(); vendedorParcela.set_Repasse(null); decimal num = new decimal(); vendedorParcela.set_ValorRepasse(new decimal?(num)); vendedorParcela.set_Vendedor(vendedor); num = new decimal(); vendedorParcela.set_PorcentagemRepasse(new decimal?(num)); vendedorParcela.set_TipoVendedor(Recursos.TipoVendedor.First((TipoVendedor x) => x.get_Id() == (long)1)); return vendedorParcela; } public async Task SelecionaCliente(Cliente value) { ObservableCollection observableCollection; long id; Visibility visibility; Visibility visibility1; List nums; if (value != null && value.get_Id() != 0) { observableCollection = await this._apoliceServico.BuscarApolicesComissao(value.get_Id(), this.SelectedStatus); this.FiltroApolice = string.Empty; id = this.SelectedExtrato.get_Seguradora().get_Id(); if (id <= (long)544) { if (id <= (long)310) { if (id <= (long)182) { if (id > (long)93) { if (id - (long)112 > (long)1) { goto Label15; } nums = new List() { (long)112, (long)113 }; goto Label11; } else { if (id == (long)28) { goto Label4; } if (id - (long)89 > (long)4) { goto Label12; } List nums1 = new List() { (long)89, (long)90, (long)91, (long)92, (long)93 }; nums = nums1; goto Label11; } } else if (id > (long)261) { if (id - (long)291 <= (long)1 || id == (long)296) { goto Label0; } if (id == (long)310) { goto Label5; } } else { if (id == (long)216) { goto Label9; } if (id - (long)258 <= (long)3) { goto Label8; } } } else if (id <= (long)400) { if (id > (long)331) { if (id == (long)341) { goto Label6; } if (id == (long)374) { goto Label7; } if (id == (long)400) { goto Label0; } } else { if (id == (long)328) { goto Label3; } if (id == (long)331) { goto Label1; } } } else if (id > (long)480) { if (id != (long)501) { goto Label13; } List nums2 = new List() { (long)498, (long)499, (long)500, (long)501, (long)502 }; nums = nums2; goto Label11; } else { if (id == (long)402) { goto Label0; } if (id != (long)480) { goto Label12; } List nums3 = new List() { (long)475, (long)476, (long)477, (long)478, (long)479, (long)480, (long)481, (long)482, (long)483, (long)484, (long)485, (long)486, (long)487, (long)558, (long)580, (long)664 }; nums = nums3; goto Label11; } } else if (id > (long)630) { if (id <= (long)674) { if (id > (long)643) { if (id == (long)649) { goto Label4; } if (id == (long)650) { goto Label5; } if (id == (long)674) { goto Label0; } } else { if (id == (long)631) { goto Label6; } long num = id - (long)639; if (num <= (long)4) { switch ((uint)num) { case 0: { goto Label5; } case 2: case 4: { goto Label0; } } } else { } } } else if (id > (long)711) { if (id == (long)884) { goto Label0; } if (id == (long)982) { goto Label1; } if (id == (long)1006) { goto Label2; } } else { if (id == (long)694) { goto Label0; } if (id == (long)711) { goto Label3; } } } else if (id > (long)562) { if (id > (long)574) { if (id == (long)578) { goto Label7; } long num1 = id - (long)591; if (num1 <= (long)7) { switch ((uint)num1) { case 0: case 1: case 3: { goto Label4; } case 2: case 5: case 6: { goto Label12; } case 4: { goto Label1; } case 7: { goto Label8; } } } else { } if (id == (long)630) { goto Label5; } } else { if (id == (long)570) { goto Label8; } if (id == (long)574) { goto Label0; } } } else if (id > (long)552) { if (id - (long)554 <= (long)1) { goto Label0; } if (id == (long)560) { goto Label9; } if (id == (long)562) { goto Label1; } } else if (id == (long)548 || id == (long)552) { goto Label10; } List nums4 = new List() { this.SelectedExtrato.get_Seguradora().get_Id() }; nums = nums4; goto Label11; } ComissaoViewModel.u003cu003ec__DisplayClass211_0 variable = null; return; List nums5 = new List() { (long)70, (long)291, (long)292, (long)296, (long)400, (long)401, (long)402, (long)554, (long)555, (long)574, (long)641, (long)643, (long)674, (long)694, (long)884, (long)348 }; nums = nums5; goto Label11; List nums6 = new List() { (long)331, (long)543, (long)562, (long)595, (long)982 }; nums = nums6; goto Label11; nums = new List() { (long)182, (long)1006 }; Label11: ComissaoViewModel comissaoViewModel = this; IEnumerable documentos = observableCollection.Where((Documento x) => { if (x.get_Controle().get_Seguradora() == null) { return false; } return nums.Contains(x.get_Controle().get_Seguradora().get_Id()); }); IOrderedEnumerable vigencia2 = from x in documentos orderby x.get_Vigencia2() select x; comissaoViewModel.TodasApolices = new ObservableCollection(vigencia2.ThenBy((Documento x) => x.get_Controle().get_Id())); this.Apolices = this.TodasApolices; ComissaoViewModel comissaoViewModel1 = this; visibility = (this.TodasApolices.Count > 0 ? Visibility.Visible : Visibility.Collapsed); comissaoViewModel1.IsVisibleApolice = visibility; ComissaoViewModel comissaoViewModel2 = this; visibility1 = (this.TodasApolices.Count > 0 ? Visibility.Collapsed : Visibility.Visible); comissaoViewModel2.IsVisibleMensagem = visibility1; variable = null; return; List nums7 = new List() { (long)328, (long)329, (long)711 }; nums = nums7; goto Label11; List nums8 = new List() { (long)28, (long)591, (long)592, (long)594, (long)649 }; nums = nums8; goto Label11; List nums9 = new List() { (long)310, (long)630, (long)639, (long)650 }; nums = nums9; goto Label11; nums = new List() { (long)341, (long)631 }; goto Label11; nums = new List() { (long)374, (long)578 }; goto Label11; List nums10 = new List() { (long)258, (long)259, (long)260, (long)261, (long)570, (long)598, (long)472, (long)595, (long)741, (long)982 }; nums = nums10; goto Label11; nums = new List() { (long)560, (long)216 }; goto Label11; List nums11 = new List() { (long)544, (long)548, (long)552 }; nums = nums11; goto Label11; Label13: if (id == (long)543) { goto Label1; } if (id == (long)544) { goto Label10; } goto Label12; goto Label12; Label15: if (id == (long)182) { goto Label2; } goto Label12; goto Label12; } public async Task SelecionaDocumento(Documento value) { if (value != null && value.get_Id() != 0) { this.SelectedDocumento = this.Apolices.FirstOrDefault((Documento x) => x.get_Id() == value.get_Id()); this.Parcelas = await this._parcelaServico.BuscarParcelasAsync(value.get_Id()); } } public async Task SelecionaExtrato(Extrato extrato) { if (extrato != null && extrato.get_Id() != 0) { base.Loading(true); this.IsVisibleDetalhes = Visibility.Collapsed; this.SelectedExtrato = extrato; this.PesquisaPagamento = string.Empty; await this.CarregaDetalhes(extrato); this.IsVisibleDetalhes = Visibility.Visible; base.Loading(false); } } private void SelecionaNormal() { ExtensionMethods.ForEach(this.DetalheExtrato, (Gestor.Model.Domain.Seguros.DetalheExtrato detalhe) => detalhe.IsNormal = detalhe.get_SubTipo().GetValueOrDefault() == 1); } public void SelecionaParcela(Parcela value) { if (value == null || value.get_Id() == 0) { return; } this.SelectedParcela = this.Parcelas.FirstOrDefault((Parcela x) => x.get_Id() == value.get_Id()); } private void Selecionar(bool value) { ExtensionMethods.ForEach(this.DetalheExtratoFiltrados, (Gestor.Model.Domain.Seguros.DetalheExtrato x) => x.set_Selecionado(value)); } public async void SelecionaSeguradora(Seguradora value, StatusExtrato status, Extrato extrato = null) { StatusExtrato statusExtrato; ObservableCollection observableCollection; bool count; Extrato extrato1; if (!this.Carregando) { if (this.Inicio <= this.Fim) { this.Filtro = string.Empty; this.FiltroApolice = string.Empty; if (value != null) { base.Loading(true); this.IsVisibleExtrato = Visibility.Collapsed; this.BaixarPendentes = status == 1; this.DetalheExtrato = null; if (status == 2) { statusExtrato = 3; } else { statusExtrato = status; } StatusExtrato statusExtrato1 = statusExtrato; List extratos = await this._servico.BuscarExtrato(value.get_Id(), this.SelectedUsuario.get_Id(), statusExtrato1, this.Inicio, this.Fim); ComissaoViewModel comissaoViewModel = this; if (status == 2) { List extratos1 = extratos; observableCollection = new ObservableCollection( from x in extratos1 where !x.get_Completo() select x); } else if (status == 3) { List extratos2 = extratos; observableCollection = new ObservableCollection( from x in extratos2 where x.get_Completo() select x); } else { observableCollection = new ObservableCollection(extratos); } comissaoViewModel.Extratos = observableCollection; this.ExtratosFiltrados = this.Extratos; if (this.FiltroPersonalizado.Count > 0) { this.FiltrarExtrato(); } ComissaoViewModel comissaoViewModel1 = this; ObservableCollection extratosFiltrados = this.ExtratosFiltrados; if (extratosFiltrados != null) { count = extratosFiltrados.Count > 0; } else { count = false; } comissaoViewModel1.IsExpanded = count; extrato1 = (extrato == null ? this.ExtratosFiltrados.FirstOrDefault() : this.ExtratosFiltrados.FirstOrDefault((Extrato x) => x.get_Id() == extrato.get_Id())); await this.SelecionaExtrato(extrato1); base.Loading(false); if (this.SelectedSeguradora != null) { string str = string.Format("CONSULTOU COMISSÃO AUTOMÁTICA NO PERÍODO ENTRE {0:d} E {1:d}", this.Inicio, this.Fim); long num = (long)0; TipoTela? nullable = new TipoTela?(35); object[] nome = new object[] { this.SelectedUsuario.get_Nome(), this.SelectedUsuario.get_Id(), this.SelectedSeguradora.get_Nome(), this.SelectedSeguradora.get_Id(), ValidationHelper.GetDescription(this.SelectedStatusExtrato), ValidationHelper.Join(this.FiltroPersonalizado, ", ") }; base.RegistrarAcao(str, num, nullable, string.Format("USUÁRIO IMPORTAÇÃO: {0} ({1})\nSEGURADORA: {2} ({3})\nSTATUS: {4}\nPESQUISA PERSONALIZADA: \"{5}\"", nome)); } } else { this.Extratos = null; this.ExtratosFiltrados = null; this.DetalheExtrato = null; this.DetalheExtratoFiltrados = null; this.SelectedExtrato = null; this.SelectedDetalhe = null; } } else { await base.ShowMessage("DATA DE INÍCIO NÃO PODE SER MAR QUE A DATA FINAL", "OK", "", false); } } } public void SelecionaSeguradoras() { base.Loading(true); List list = ( from x in Recursos.Seguradoras where x.get_Ativo() orderby x.get_Nome() select x).ToList(); Seguradora seguradora = new Seguradora(); seguradora.set_Id((long)0); seguradora.set_Nome("TODAS AS SEGURADORAS"); seguradora.set_NomeSocial("TODAS DAS SEGURADORAS"); list.Insert(0, seguradora); List usuarios = ( from x in Recursos.Usuarios where !x.get_Excluido() orderby x.get_IdEmpresa(), x.get_Nome() select x).ToList(); Usuario usuario = new Usuario(); usuario.set_Id((long)0); usuario.set_Nome("TODOS OS USUÁRIOS"); usuarios.Insert(0, usuario); this.Usuarios = new ObservableCollection(usuarios); this.Seguradoras = new ObservableCollection(list); base.Loading(false); } private async void WorkOnSelectedCliente(Cliente value) { if (value == null || value.get_Id() == 0) { this.IsVisibleCliente = Visibility.Collapsed; this.IsVisibleApolice = Visibility.Collapsed; this.IsVisibleMensagem = Visibility.Collapsed; this.DocumentoPrincipal = string.Empty; this.SelectedDocumento = null; this.SelectedParcela = null; } else { this.IsVisibleCliente = Visibility.Visible; if (!this.Buscando) { base.Loading(true); this.IsVisibleDetalhes = Visibility.Collapsed; } if (!this.Buscando) { this.Buscando = true; await this.SelecionaCliente(value); await this.SelecionaDocumento(this.Apolices.FirstOrDefault()); this.Buscando = false; Cliente cliente = value; TipoDocumento? documentoPrincipal = value.get_DocumentoPrincipal(); cliente.set_DocumentoPrincipal(new TipoDocumento?(documentoPrincipal.GetValueOrDefault())); documentoPrincipal = value.get_DocumentoPrincipal(); if (documentoPrincipal.HasValue) { switch (documentoPrincipal.GetValueOrDefault()) { case 0: { ComissaoViewModel comissaoViewModel = this; string documento = value.get_Documento(); if (documento == null) { documento = ""; } comissaoViewModel.DocumentoPrincipal = documento; break; } case 1: { ComissaoViewModel comissaoViewModel1 = this; string rne = value.get_Rne(); if (rne == null) { rne = ""; } comissaoViewModel1.DocumentoPrincipal = rne; break; } case 2: { ComissaoViewModel comissaoViewModel2 = this; string cei = value.get_Cei(); if (cei == null) { cei = ""; } comissaoViewModel2.DocumentoPrincipal = cei; break; } } } this.IsVisibleDetalhes = Visibility.Visible; base.Loading(false); } } } private void WorkOnSelectedDocumento(Documento value) { if (value == null || value.get_Id() == 0 || this.Buscando) { return; } TipoRecebimento? tipoRecebimento = value.get_TipoRecebimento(); this.IsFatura = tipoRecebimento.GetValueOrDefault() == 2; } public async void WorkOnSelectedStatus() { if (this.SelectedCliente != null) { if (!this.Buscando) { await this.SelecionaCliente(this.SelectedCliente); } } } } }