using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using System.Windows; using Gestor.Application.Actions; using Gestor.Application.Drawers; 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.Servicos.Seguros.Itens; using Gestor.Application.ViewModels.Seguros; using Gestor.Common.Validation; using Gestor.Model.Common; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Configuracoes; using Gestor.Model.Domain.Ferramentas; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using Gestor.Model.Helper; namespace Gestor.Application.ViewModels.Generic; public class BaseApoliceViewModel : BaseSegurosViewModel { internal ApoliceServico Servico; internal PerfilServico PerfilServico; internal RamoServico RamoServico; internal SeguradoraServico SeguradoraServico; internal VendedorServico VendedorServico; internal ParcelaServico ParcelaServico; internal ProdutoServico ProdutoServico; internal EstipulanteServico EstipulanteServico; internal TarefaServico TarefaServico; private bool _invoke = true; public bool UpdatePremio; private bool _enableControle = true; private bool _apelido; private bool _controleAdm; private Documento _selectedDocumento; private Visibility _visibilityExcluirParcela = (Visibility)2; private Visibility _visibilityReplicarFatura = (Visibility)2; private Visibility _visibilityAlterarVencimento; private string _importado = "CLIQUE PARA VER INFORMAÇÕES SOBRE A INCLUSÃO"; private string _codigoDocumento; private DateTime? _emissaoDocumento; private DateTime? _transmissaoDocumento; private bool _editandoParcela; private bool _botoesParcelaEnabled = true; private List _vendedores; private List _todosVendedores; private ObservableCollection _pagamentos; private ObservableCollection _situacao = new ObservableCollection(new List { (TipoSeguro)1, (TipoSeguro)2, (TipoSeguro)5 }); private ObservableCollection _tipoEndosso = new ObservableCollection(new List { (TipoEndosso)0, (TipoEndosso)1, (TipoEndosso)2, (TipoEndosso)4, (TipoEndosso)3 }); private Parcela _selectedParcela; private bool _coCorretagem; private Visibility _baixarParcelaVisibility = (Visibility)2; private ObservableCollection _parcelas; private decimal _gerada; private decimal _comissOriginal; private Visibility _comissOriginalVisibility = (Visibility)2; private decimal _recebida; private decimal _pendente; private decimal _repasse; private Visibility _recusaVisibility; private string _excluirParcelaLabel = "EXCLUIR BAIXA"; private bool _isEnableSituacao; private List _produtos = Recursos.Produtos; private List _status = Recursos.Status; private List _ramos; private List _seguradorasAnteriores; private List _seguradoras; private Visibility _isRenovacaoVisibility = (Visibility)2; private bool _isEndosso; private bool _enableAlterarSituacao; private string _assinada = "PROPOSTA ASSINADA"; private string _conferida = "APÓLICE CONFERIDA"; private string _transmissao = "TRANSMISSÃO DE PROPOSTA"; private string _emissao = "EMISSÃO DA APÓLICE"; private List _tiposVendedor = Recursos.TipoVendedor?.Where((TipoVendedor x) => !x.Ativo.HasValue || x.Ativo.Value).ToList(); private List _estipulantes; public Documento CancelDocumento; private List _repasses; private List _repassesVendedores; private List _repassesVendedor; private VendedorParcela _selectedPagamento; private bool _baixarParcelas; private bool _isFatura; private bool _ultimaFatura; private bool _allowEditVendedor = true; private bool _alteracaoEnabled = true; private bool _allowEditEmissao = true; private bool _allowEditApolice = true; private bool _allowVigenciaFinal = true; private bool _novaApolice; private bool _renovar; public decimal Tolerancia; private bool _enableRepasse; private bool _bloquearObservacao = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 39); private string _editarParcelasLabel = "EDITAR PARCELAS"; private string _anotacoes; private int _quantidadeFaturas; private double _tamanhoGrid; private bool _inclusao; private bool _criandoParcelaEspecial; private bool _visibilityLogAntigo = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 22); internal Documento DocumentoSelecionado { get; set; } internal long ParcelaSelecionada { get; set; } public bool Invoke { get { return _invoke; } set { _invoke = value; OnPropertyChanged("Invoke"); } } public bool EnableControle { get { return _enableControle; } set { _enableControle = value; OnPropertyChanged("EnableControle"); } } public AcessoApolice Acesso { get; set; } public bool Apelido { get { return _apelido; } set { _apelido = value; OnPropertyChanged("Apelido"); } } public bool ControleAdm { get { return _controleAdm; } set { _controleAdm = value; OnPropertyChanged("ControleAdm"); } } public Documento SelectedDocumento { get { return _selectedDocumento; } set { if (value != null && ((DomainBase)value).Id == 0L) { VisibilityLogAntigo = false; } _selectedDocumento = value; Anotacoes = string.Empty; base.EnableButtons = value != null && ((DomainBase)value).Id > 0; base.EnableIncluir = value == null || ((DomainBase)value).Id > 0; bool flag = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 13); base.EnableEndossar = value != null && ((DomainBase)value).Id > 0 && (flag || (!string.IsNullOrWhiteSpace(value.Apolice) && !string.IsNullOrWhiteSpace(value.Proposta) && value.Emissao.HasValue)); base.EnableRenovar = value != null && ((DomainBase)value).Id > 0 && value.Vigencia2.HasValue && !string.IsNullOrWhiteSpace(value.Apolice); if (value == null || ((DomainBase)value).Id == 0L) { ZeraComissao(); } CodigoDocumento = ((SelectedDocumento == null || ((DomainBase)SelectedDocumento).Id == 0L) ? "" : $"{((DomainBase)SelectedDocumento).Id}"); if (value != null && value.Status == null && Status.First().Nome == "SEM STATUS") { value.Status = Status.First(); } EmissaoDocumento = ((value != null && value.Emissao.HasValue) ? value.Emissao : new DateTime?(Funcoes.GetNetworkTime().Date)); TransmissaoDocumento = ((value != null && value.Remessa.HasValue) ? value.Remessa : new DateTime?(Funcoes.GetNetworkTime().Date)); RecusaVisibility = (Visibility)((Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 19) && !string.IsNullOrWhiteSpace((value != null) ? value.Apolice : null) && value.Emissao.HasValue) ? 2 : 0); VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); OnPropertyChanged("SelectedDocumento"); } } public Visibility VisibilityExcluirParcela { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _visibilityExcluirParcela; } 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) _visibilityExcluirParcela = value; OnPropertyChanged("VisibilityExcluirParcela"); } } public Visibility VisibilityReplicarFatura { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _visibilityReplicarFatura; } 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) _visibilityReplicarFatura = value; OnPropertyChanged("VisibilityReplicarFatura"); } } public Visibility VisibilityAlterarVencimento { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _visibilityAlterarVencimento; } 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) _visibilityAlterarVencimento = value; OnPropertyChanged("VisibilityAlterarVencimento"); } } public string Importado { get { return _importado; } set { _importado = value; OnPropertyChanged("Importado"); } } public string CodigoDocumento { get { return _codigoDocumento; } set { _codigoDocumento = value; OnPropertyChanged("CodigoDocumento"); } } public DateTime? EmissaoDocumento { get { return _emissaoDocumento; } set { _emissaoDocumento = value; OnPropertyChanged("EmissaoDocumento"); } } public DateTime? TransmissaoDocumento { get { return _transmissaoDocumento; } set { _transmissaoDocumento = value; OnPropertyChanged("TransmissaoDocumento"); } } public bool EditandoParcela { get { return _editandoParcela; } set { _editandoParcela = value; OnPropertyChanged("EditandoParcela"); } } public bool BotoesParcelaEnabled { get { return _botoesParcelaEnabled; } set { _botoesParcelaEnabled = value; OnPropertyChanged("BotoesParcelaEnabled"); } } public List Vendedores { get { return _vendedores; } set { _vendedores = value; OnPropertyChanged("Vendedores"); } } public List TodosVendedores { get { return _todosVendedores; } set { _todosVendedores = value; OnPropertyChanged("TodosVendedores"); } } public ObservableCollection Pagamentos { get { return _pagamentos; } set { _pagamentos = value; OnPropertyChanged("Pagamentos"); } } public ObservableCollection Situacao { get { return _situacao; } set { _situacao = value; OnPropertyChanged("Situacao"); } } public ObservableCollection TipoEndossoList { get { return _tipoEndosso; } set { _tipoEndosso = value; OnPropertyChanged("TipoEndossoList"); } } public Parcela SelectedParcela { get { return _selectedParcela; } set { _selectedParcela = value; WorkOnSelectedParcela(value); OnPropertyChanged("SelectedParcela"); } } public bool CoCorretagem { get { return _coCorretagem; } set { if (SelectedPagamento != null) { SelectedPagamento.CoCorretagem = value; } _coCorretagem = value; OnPropertyChanged("CoCorretagem"); } } public Visibility BaixarParcelaVisibility { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _baixarParcelaVisibility; } set { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (!Restricao((TipoRestricao)15)) { _baixarParcelaVisibility = value; OnPropertyChanged("BaixarParcelaVisibility"); } } } public ObservableCollection Parcelas { get { return _parcelas; } set { _parcelas = value; if (value != null && value.Count == 0) { VisibilityExcluirParcela = (Visibility)2; VisibilityReplicarFatura = (Visibility)2; BaixarParcelaVisibility = (Visibility)2; VisibilityAlterarVencimento = (Visibility)2; } OnPropertyChanged("Parcelas"); } } public decimal Gerada { get { return _gerada; } set { _gerada = value; OnPropertyChanged("Gerada"); } } public decimal ComissOriginal { get { return _comissOriginal; } set { ComissOriginalVisibility = (Visibility)((!VerificaCoCorretagem()) ? 2 : 0); _comissOriginal = value; OnPropertyChanged("ComissOriginal"); } } public Visibility ComissOriginalVisibility { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _comissOriginalVisibility; } 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) _comissOriginalVisibility = value; OnPropertyChanged("ComissOriginalVisibility"); } } public decimal Recebida { get { return _recebida; } set { _recebida = value; OnPropertyChanged("Recebida"); } } public decimal Pendente { get { return _pendente; } set { _pendente = value; OnPropertyChanged("Pendente"); } } public decimal Repasse { get { return _repasse; } set { _repasse = value; OnPropertyChanged("Repasse"); } } public Visibility RecusaVisibility { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _recusaVisibility; } set { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) _recusaVisibility = (Visibility)(Restricao((TipoRestricao)18) ? 2 : ((int)value)); OnPropertyChanged("RecusaVisibility"); } } public bool Loaded { get; set; } public string ExcluirParcelaLabel { get { return _excluirParcelaLabel; } set { _excluirParcelaLabel = value; OnPropertyChanged("ExcluirParcelaLabel"); } } public bool IsEnableSituacao { get { return _isEnableSituacao; } set { _isEnableSituacao = value; OnPropertyChanged("IsEnableSituacao"); } } public List Produtos { get { return _produtos; } set { _produtos = value; OnPropertyChanged("Produtos"); } } public List Status { get { return _status; } set { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown if (value.All((Status x) => x.Nome != "SEM STATUS")) { value.Insert(0, new Status { Nome = "SEM STATUS", Id = 0L, Ativo = true }); } _status = value; OnPropertyChanged("Status"); } } public List Ramos { get { return _ramos; } set { _ramos = value; OnPropertyChanged("Ramos"); } } public List SeguradorasAnteriores { get { return _seguradorasAnteriores; } set { _seguradorasAnteriores = value; OnPropertyChanged("SeguradorasAnteriores"); } } public List Seguradoras { get { return _seguradoras; } set { _seguradoras = value; OnPropertyChanged("Seguradoras"); } } public Visibility IsRenovacaoVisibility { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _isRenovacaoVisibility; } 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) _isRenovacaoVisibility = value; OnPropertyChanged("IsRenovacaoVisibility"); } } public bool IsEndosso { get { return _isEndosso; } set { _isEndosso = value; WorkOnSelectedTipo(value); OnPropertyChanged("IsEndosso"); } } public bool EnableAlterarSituacao { get { return _enableAlterarSituacao; } set { _enableAlterarSituacao = value; OnPropertyChanged("EnableAlterarSituacao"); } } public string Assinada { get { return _assinada; } set { _assinada = value; OnPropertyChanged("Assinada"); } } public string Conferida { get { return _conferida; } set { _conferida = value; OnPropertyChanged("Conferida"); } } public string Transmissao { get { return _transmissao; } set { _transmissao = value; OnPropertyChanged("Transmissao"); } } public string Emissao { get { return _emissao; } set { _emissao = value; OnPropertyChanged("Emissao"); } } public List TiposVendedor { get { return _tiposVendedor; } set { _tiposVendedor = value; OnPropertyChanged("TiposVendedor"); } } public List Estipulantes { get { return _estipulantes; } set { _estipulantes = value; OnPropertyChanged("Estipulantes"); } } public List Repasses { get { return _repasses; } set { _repasses = value; OnPropertyChanged("Repasses"); } } public List RepassesVendedores { get { return _repassesVendedores; } set { _repassesVendedores = value; OnPropertyChanged("RepassesVendedores"); } } public List RepassesVendedor { get { return _repassesVendedor; } set { _repassesVendedor = value; EnableRepasse = value != null && value.Count > 0; OnPropertyChanged("RepassesVendedor"); } } public VendedorParcela SelectedPagamento { get { return _selectedPagamento; } set { _selectedPagamento = value; OnPropertyChanged("SelectedPagamento"); } } public bool BaixarParcelas { get { return _baixarParcelas; } set { _baixarParcelas = value; OnPropertyChanged("BaixarParcelas"); } } public bool IsFatura { get { return _isFatura; } set { _isFatura = value; OnPropertyChanged("IsFatura"); } } public bool UltimaFatura { get { return _ultimaFatura; } set { _ultimaFatura = value; OnPropertyChanged("UltimaFatura"); } } public bool AllowEditVendedor { get { return _allowEditVendedor; } set { _allowEditVendedor = _incluirPermissEnabled && value; OnPropertyChanged("AllowEditVendedor"); } } public bool AlteracaoEnabled { get { return _alteracaoEnabled; } set { _alteracaoEnabled = value; OnPropertyChanged("AlteracaoEnabled"); } } public bool AllowEditEmissao { get { return _allowEditEmissao; } set { _allowEditEmissao = value; OnPropertyChanged("AllowEditEmissao"); } } public bool AllowEditApolice { get { return _allowEditApolice; } set { _allowEditApolice = value; AllowVigenciaFinal = value || IsFatura; OnPropertyChanged("AllowEditApolice"); } } public bool AllowVigenciaFinal { get { return _allowVigenciaFinal; } set { _allowVigenciaFinal = value; OnPropertyChanged("AllowVigenciaFinal"); } } private Documento DocumentoRenovado { get; set; } public bool NovaApolice { get { return _novaApolice; } set { _novaApolice = value; OnPropertyChanged("NovaApolice"); } } public bool Renovar { get { return _renovar; } set { _renovar = value; OnPropertyChanged("Renovar"); } } public bool EnableRepasse { get { return _enableRepasse; } set { _enableRepasse = value; OnPropertyChanged("EnableRepasse"); } } public bool BloquearObservacao { get { return _bloquearObservacao; } set { _bloquearObservacao = value; OnPropertyChanged("BloquearObservacao"); } } public string EditarParcelasLabel { get { return _editarParcelasLabel; } set { _editarParcelasLabel = value; OnPropertyChanged("EditarParcelasLabel"); } } public new string Anotacoes { get { return _anotacoes; } set { _anotacoes = value; OnPropertyChanged("Anotacoes"); } } public int QuantidadeFaturas { get { return _quantidadeFaturas; } set { if (value < 0) { value = 0; } if (value > 12) { value = 12; } _quantidadeFaturas = value; OnPropertyChanged("QuantidadeFaturas"); } } public double TamanhoGrid { get { return _tamanhoGrid; } set { _tamanhoGrid = value; OnPropertyChanged("TamanhoGrid"); } } public bool Inclusao { get { return _inclusao; } set { _inclusao = value; OnPropertyChanged("Inclusao"); } } public bool CriandoParcelaEspecial { get { return _criandoParcelaEspecial; } set { _criandoParcelaEspecial = value; } } public Imposto Imposto { get; set; } public bool VisibilityLogAntigo { get { return _visibilityLogAntigo; } set { _visibilityLogAntigo = value; OnPropertyChanged("VisibilityLogAntigo"); } } public BaseApoliceViewModel() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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) Servico = new ApoliceServico(); VendedorServico = new VendedorServico(); ParcelaServico = new ParcelaServico(); RamoServico = new RamoServico(); SeguradoraServico = new SeguradoraServico(); ProdutoServico = new ProdutoServico(); EstipulanteServico = new EstipulanteServico(); TarefaServico = new TarefaServico(); PerfilServico = new PerfilServico(); Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 6); ControleAdm = Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 33) || Recursos.Usuario.Administrador; } public async Task Importacao() { List importados = await new CriticaApoliceServico().BuscarImportacao(((DomainBase)SelectedDocumento).Id); List list = (await new LogServico().FindByEntityId((TipoTela)2, ((DomainBase)SelectedDocumento).Id)).ToList(); RegistroLog val = ((list.Count > 0) ? list.Last() : null); switch (importados.Count) { case 0: { BaseApoliceViewModel baseApoliceViewModel = this; string importado; if (SelectedDocumento.DataCriacao.HasValue) { Usuario usuarioCriacao = SelectedDocumento.UsuarioCriacao; importado = $"CADASTRO MANUAL: {((usuarioCriacao != null) ? usuarioCriacao.Nome : null)} - {SelectedDocumento.DataCriacao:dd/MM/yyyy 'ÀS' HH:mm:ss}"; } else { importado = $"CADASTRO MANUAL: {((val != null) ? val.Usuario.Nome : null)} - {((val != null) ? new DateTime?(val.DataHora) : null):dd/MM/yyyy 'ÀS' HH:mm:ss}"; } baseApoliceViewModel.Importado = importado; break; } case 1: if (string.IsNullOrWhiteSpace(importados[0].Tipo) || importados[0].Tipo == "0") { Importado = ((!importados[0].Aggilizador.HasValue || !importados[0].Aggilizador.Value) ? $"IMPORTAÇÃO DA PROPOSTA: {importados[0].UsuarioImportacao.Nome} - {importados[0].DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}" : $"IMPORTAÇÃO DA PROPOSTA VIA AGGILIZADOR: {importados[0].UsuarioImportacao.Nome} - {importados[0].DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}"); } if (importados[0].Tipo == "1") { if (!SelectedDocumento.DataCriacao.HasValue) { Importado = $"CADASTRO MANUAL DA PROPOSTA: {((val != null) ? val.Usuario.Nome : null)} - {((val != null) ? new DateTime?(val.DataHora) : null):dd/MM/yyyy 'ÀS' HH:mm:ss}\n"; } else if (importados[0].DataImportacao.HasValue && DateTime.Compare(SelectedDocumento.DataCriacao.Value, importados[0].DataImportacao.Value) < 0) { Importado = $"CADASTRO MANUAL DA PROPOSTA: {SelectedDocumento.UsuarioCriacao} - {SelectedDocumento.DataCriacao:dd/MM/yyyy 'ÀS' HH:mm:ss}\n"; } if (SelectedDocumento.DataCriacao <= importados[0].DataImportacao) { Importado = ((!importados[0].Aggilizador.HasValue || !importados[0].Aggilizador.Value) ? $"IMPORTAÇÃO DA APÓLICE: {importados[0].UsuarioImportacao.Nome} - {importados[0].DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}" : $"IMPORTAÇÃO DA APÓLICE VIA AGGILIZADOR: {importados[0].UsuarioImportacao.Nome} - {importados[0].DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}"); } } if (importados[0].Tipo == "2") { if (!SelectedDocumento.DataCriacao.HasValue) { Importado = $"CADASTRO MANUAL DA PROPOSTA: {((val != null) ? val.Usuario.Nome : null)} - {((val != null) ? new DateTime?(val.DataHora) : null):dd/MM/yyyy 'ÀS' HH:mm:ss}\n"; } else if (importados[0].DataImportacao.HasValue && DateTime.Compare(SelectedDocumento.DataCriacao.Value, importados[0].DataImportacao.Value) < 0) { Importado = $"CADASTRO MANUAL DA PROPOSTA: {SelectedDocumento.UsuarioCriacao} - {SelectedDocumento.DataCriacao:dd/MM/yyyy 'ÀS' HH:mm:ss}\n"; } if (SelectedDocumento.DataCriacao <= importados[0].DataImportacao) { Importado = ((!importados[0].Aggilizador.HasValue || !importados[0].Aggilizador.Value) ? $"IMPORTAÇÃO DO ENDOSSO: {importados[0].UsuarioImportacao.Nome} - {importados[0].DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}" : $"IMPORTAÇÃO DO ENDOSSO VIA AGGILIZADOR: {importados[0].UsuarioImportacao.Nome} - {importados[0].DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}"); } } break; case 2: case 3: { CriticaApolice val2 = importados.Find((CriticaApolice x) => string.IsNullOrWhiteSpace(x.Tipo) || x.Tipo == "0"); CriticaApolice val3 = importados.Find((CriticaApolice x) => x.Tipo == "1"); Importado = ((!val2.Aggilizador.HasValue || !val2.Aggilizador.Value) ? $"IMPORTAÇÃO DA PROPOSTA: {val2.UsuarioImportacao.Nome} - {val2.DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}\n" : $"IMPORTAÇÃO DA PROPOSTA VIA AGGILIZADOR: {val2.UsuarioImportacao.Nome} - {val2.DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}\n"); if (val3 != null) { Importado += ((!val3.Aggilizador.HasValue || !val3.Aggilizador.Value) ? $"IMPORTAÇÃO DA APÓLICE: {val3.UsuarioImportacao.Nome} - {val3.DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}" : $"IMPORTAÇÃO DA APÓLICE VIA AGGILIZADOR: {val3.UsuarioImportacao.Nome} - {val3.DataImportacao:dd/MM/yyyy 'ÀS' HH:mm:ss}"); } break; } } } private void WorkOnSelectedParcela(Parcela value) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Invalid comparison between Unknown and I4 //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Invalid comparison between Unknown and I4 //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Invalid comparison between Unknown and I4 //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Invalid comparison between Unknown and I4 if (value == null || ((DomainBase)value).Id == 0L || SelectedDocumento == null) { return; } bool flag = Repasses.Any((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id && x.DataPagamento.HasValue); if ((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) { AllowEditEmissao = (Repasses?.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id && x.Repasse != null && (int)x.Repasse.Base.GetValueOrDefault() == 4).All((VendedorParcela x) => !x.DataPagamento.HasValue)).Value; } if ((int)value.SubTipo == 1 && (int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) { BaixarParcelaVisibility = (Visibility)((!Parcelas.Any((Parcela x) => !x.DataRecebimento.HasValue && (int)x.SubTipo == 1)) ? 2 : 0); Parcela val = ((IEnumerable)Parcelas.OrderBy((Parcela x) => x.NumeroParcela)).LastOrDefault((Func)((Parcela x) => x.DataRecebimento.HasValue && (int)x.SubTipo == 1 && (x.ValorComissao != 0m || x.ValorRealizado != 0m))); VisibilityExcluirParcela = (Visibility)(flag ? 2 : (((!value.DataRecebimento.HasValue || val != null) && !(((val != null) ? new int?(val.NumeroParcela) : null) <= value.NumeroParcela)) ? 2 : 0)); ExcluirParcelaLabel = "EXCLUIR BAIXA"; } else { BaixarParcelaVisibility = (Visibility)(value.DataRecebimento.HasValue ? 2 : 0); VisibilityExcluirParcela = (Visibility)(flag ? 2 : 0); ExcluirParcelaLabel = (value.DataRecebimento.HasValue ? "EXCLUIR BAIXA" : (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? "EXCLUIR PARCELA" : "EXCLUIR FATURA")); } VisibilityReplicarFatura = (Visibility)((!IsFatura) ? 2 : 0); } private void ZeraComissao() { Gerada = 0m; Recebida = 0m; Pendente = 0m; Repasse = 0m; ComissOriginal = 0m; } public async void Seleciona(Documento documento) { Loading(isLoading: true); await PermissaoTela((TipoTela)2); await PermissaoTela((TipoTela)5); if (documento == null || documento != SelectedDocumento) { await SelecionaDocumento(documento); } Gestor.Application.Actions.Actions.Redimencionar?.Invoke(Invoke); Loading(isLoading: false); } public async Task BuscarVendedores(bool verificarRamo = true) { if (RepassesVendedores == null) { RepassesVendedores = await VendedorServico.BuscaRepasses(); TodosVendedores = (from x in RepassesVendedores group x by ((DomainBase)x.Vendedor).Id into x select x.First().Vendedor into x orderby x.Nome select x).ToList(); } Documento selectedDocumento = SelectedDocumento; List list = ((selectedDocumento != null) ? selectedDocumento.Vendedores : null); if (list == null) { Documento selectedDocumento2 = SelectedDocumento; List list2 = ((selectedDocumento2 == null || ((DomainBase)selectedDocumento2).Id <= 0) ? new List() : (await ParcelaServico.BuscarVendedores(((DomainBase)SelectedDocumento).Id))); list = list2; } List vendedores = list; Vendedores = TodosVendedores.Where((Vendedor x) => (x.IdEmpresa == Recursos.Usuario.IdEmpresa || vendedores.Select((Vendedor y) => ((DomainBase)y).Id).Contains(((DomainBase)x).Id)) && x.Ativo && !x.Corretora).ToList(); List list3 = await VerificaVinculoVendedor(Recursos.Usuario); if (list3.Count > 0) { list3.ForEach(delegate(VendedorUsuario x) { vendedores.Add(x.Vendedor); }); Vendedores = vendedores; } if (!verificarRamo) { return; } Documento selectedDocumento3 = SelectedDocumento; object obj; if (selectedDocumento3 == null) { obj = null; } else { Controle controle = selectedDocumento3.Controle; obj = ((controle != null) ? controle.Ramo : null); } if (obj == null) { return; } for (int num = Vendedores.Count - 1; num >= 0; num--) { List repasses = GetRepasses(Vendedores[num]); if (!repasses.Any((Repasse x) => x.Ramo == null) && repasses.All((Repasse x) => ((DomainBase)x.Ramo).Id != ((DomainBase)SelectedDocumento.Controle.Ramo).Id)) { Vendedores.Remove(Vendedores[num]); } } } public async Task LimparRepasses() { if (Pagamentos == null) { return; } ObservableCollection pagamentos = Pagamentos; if ((pagamentos == null || pagamentos.Count != 0) && Repasses != null) { List repasses = Repasses; if ((repasses == null || repasses.Count != 0) && ((DomainBase)SelectedDocumento).Id == 0L && base.EnableFields && AllowEditApolice && AlteracaoEnabled) { await ShowMessage("REPASSES ADICIONADOS NÃO PERTENCEM AO RAMO SELECIONADO E SERÃO EXCLUÍDOS."); Pagamentos.Clear(); Repasses.Clear(); } } } public async Task SelecionaDocumento(Documento documento) { Loading(isLoading: true); base.IsEnabled = false; await BuscarVendedores(verificarRamo: false); Estipulantes = (from x in await new BaseServico().BuscarEstipulantes() where (documento != null) ? (x.IdEmpresa == documento.Controle.IdEmpresa && x.Ativo) : (x.IdEmpresa == Recursos.Usuario.IdEmpresa) orderby x.Nome select x).ToList(); SelectedDocumento = null; PreLoad(); if (documento == null) { base.EnableFields = false; Loading(isLoading: false); return; } await WorkOnSelectedDocumento(documento); if (Invoke) { long id = ((DomainBase)SelectedDocumento).Id; Documento documentoSelecionado = ConsultaViewModel.DocumentoSelecionado; if (id != ((documentoSelecionado != null) ? new long?(((DomainBase)documentoSelecionado).Id) : null)) { ConsultaViewModel.DocumentoSelecionado = SelectedDocumento; } } if ((int)Acesso == 1 && ParcelaSelecionada != 0L) { await SelecionaParcela(((IEnumerable)Parcelas).FirstOrDefault((Func)((Parcela x) => ((DomainBase)x).Id == ParcelaSelecionada))); } if (Invoke) { Loaded = true; } base.IsEnabled = true; Loading(isLoading: false); } private void PreLoad() { Ramos = Recursos.Ramos; Seguradoras = Recursos.Seguradoras; Produtos = Recursos.Produtos; Status = Recursos.Status; SeguradorasAnteriores = Recursos.Seguradoras; TipoEndossoList = new ObservableCollection(new List { (TipoEndosso)0, (TipoEndosso)1, (TipoEndosso)2, (TipoEndosso)4, (TipoEndosso)3 }); } private async Task WorkOnSelectedDocumento(Documento value) { base.IsEnabledEdit = value == null || ((DomainBase)value).Id == 0; base.IsEnabledEditEndosso = value == null || ((DomainBase)value).Id == 0; if (value != null && ((DomainBase)value).Id != 0L) { if (Situacao.All((TipoSeguro x) => x != value.Situacao)) { List list = new List { (TipoSeguro)1, (TipoSeguro)2, (TipoSeguro)5, value.Situacao }; Situacao = new ObservableCollection(list); } else { IsEnableSituacao = true; } Controle controle = value.Controle; List seguradoras = ((((controle != null) ? controle.Seguradora : null) != null) ? Recursos.Seguradoras.Where((Seguradora x) => x.Ativo || ((DomainBase)x).Id == ((DomainBase)value.Controle.Seguradora).Id).ToList() : Recursos.Seguradoras.Where((Seguradora x) => x.Ativo).ToList()); Seguradoras = seguradoras; SeguradorasAnteriores = Recursos.Seguradoras; SelectedDocumento = await Servico.BuscarApoliceAsync(((DomainBase)value).Id); if (!SelectedDocumento.NegocioCorretora.HasValue) { SelectedDocumento.NegocioCorretora = (NegocioCorretora)(((int)SelectedDocumento.Situacao == 2 && SelectedDocumento.Negocio.HasValue && (int)SelectedDocumento.Negocio.GetValueOrDefault() == 1) ? 1 : 0); OnPropertyChanged("SelectedDocumento"); } BaseApoliceViewModel baseApoliceViewModel = this; Controle controle2 = SelectedDocumento.Controle; decimal? obj; if (controle2 == null) { obj = null; } else { Seguradora seguradora = controle2.Seguradora; obj = ((seguradora != null) ? seguradora.Tolerancia : null); } decimal? num = obj; baseApoliceViewModel.Tolerancia = num.GetValueOrDefault(2m); List produtos = Recursos.Produtos.Where((Produto x) => x.Ativo || (SelectedDocumento.Controle.Produto != null && ((DomainBase)x).Id == ((DomainBase)SelectedDocumento.Controle.Produto).Id)).ToList(); Produtos = produtos; if (Invoke) { ConsultaViewModel.DocumentoSelecionado = SelectedDocumento; } Documento documento = (Documento)((DomainBase)SelectedDocumento).Clone(); await CarregarParcelas(documento); await CarregaRepasse(((DomainBase)documento).Id); ((DomainBase)SelectedDocumento).Initialize(); Initialized = true; if (Parcelas.Count == 0) { AllowEditVendedor = false; } AllowEditApolice = Parcelas.Where((Parcela x) => (int)x.SubTipo == 1).All((Parcela x) => !x.DataRecebimento.HasValue) && Repasses.Where((VendedorParcela x) => (int)x.Parcela.SubTipo == 1).All((VendedorParcela x) => !x.DataPagamento.HasValue); AllowEditEmissao = (int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2 || Repasses.Where((VendedorParcela x) => x.Repasse != null && (int)x.Repasse.Base.GetValueOrDefault() == 4).All((VendedorParcela x) => !x.DataPagamento.HasValue); CalculaComissao(SelectedDocumento, Parcelas); IsEndosso = SelectedDocumento.Tipo != 0; EnableAlterarSituacao = !SelectedDocumento.TipoEndosso.HasValue || ((int)SelectedDocumento.TipoEndosso.GetValueOrDefault() != 2 && (int)SelectedDocumento.TipoEndosso.GetValueOrDefault() != 3); EditarParcelasLabel = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? "EDITAR FATURAS" : "EDITAR PARCELAS"); base.AllowEditParcela = true; CancelDocumento = (Documento)((DomainBase)SelectedDocumento).Clone(); } } public bool VerificaCoCorretagem() { return Repasses?.Any((VendedorParcela x) => x.CoCorretagem) ?? false; } public async Task CarregarParcelas(Documento documento) { if (documento != null) { ObservableCollection observableCollection = await ParcelaServico.BuscarParcelasPorDocumento(documento); Parcelas = (IsFatura ? new ObservableCollection(observableCollection.OrderByDescending((Parcela x) => x.NumeroParcela)) : observableCollection); if (Invoke) { Gestor.Application.Actions.Actions.RecarregarParcelas?.Invoke(SelectedDocumento); } } } private void CalculaComissao(Documento documento, ObservableCollection parcelas) { decimal num = (documento.AdicionalComiss ? (documento.PremioLiquido + documento.PremioAdicional) : documento.PremioLiquido); decimal num2 = documento.Comissao * 0.01m; Gerada = num * num2; Recebida = (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 32) ? parcelas.Where((Parcela x) => (int)x.SubTipo == 1 || (int)x.SubTipo == 6).Sum((Parcela x) => x.ValorComissao) : parcelas.Where((Parcela x) => (int)x.SubTipo == 1).Sum((Parcela x) => x.ValorComissao)); Pendente = Gerada - Recebida; Pendente = ((Pendente < 0.01m) ? 0.00m : Pendente); Repasse = Repasses.Where((VendedorParcela x) => x.DataPrePagamento.HasValue && !x.CoCorretagem).Sum((VendedorParcela x) => x.ValorRepasse.GetValueOrDefault()); if (Pendente < Tolerancia) { Pendente = 0m; } if (VerificaCoCorretagem()) { Documento selectedDocumento = SelectedDocumento; ComissOriginal = ((selectedDocumento != null) ? selectedDocumento.ComissaoTotal : null).GetValueOrDefault(); } } public void ToggleSeguradoraAnterior(TipoSeguro situacao) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)situacao != 2) { IsRenovacaoVisibility = (Visibility)2; } else { IsRenovacaoVisibility = (Visibility)0; } } private void WorkOnSelectedTipo(bool value) { Assinada = (value ? "PROPOSTA DE ENDOSSO ASSINADA" : "PROPOSTA ASSINADA"); Conferida = (value ? "ENDOSSO CONFERIDO" : "APÓLICE CONFERIDA"); Transmissao = (value ? "TRANSMISSÃO DA PROPOSTA DE ENDOSSO" : "TRANSMISSÃO DA PROPOSTA"); Emissao = (value ? "EMISSÃO DO ENDOSSO" : "EMISSÃO DA APÓLICE"); } public async Task SelecionarParcelaBaixa() { if (SelectedParcela == null || SelectedDocumento == null) { return false; } if ((int)SelectedParcela.SubTipo != 1 && !SelectedParcela.DataRecebimento.HasValue) { SelectedParcela.ValorLiquidoFatura = SelectedDocumento.PremioLiquido / ((SelectedDocumento.NumeroParcelas > 0m) ? SelectedDocumento.NumeroParcelas : 1m); SelectedParcela.Baixando = true; return true; } if (IsFatura && !SelectedParcela.DataRecebimento.HasValue) { SelectedParcela.Baixando = true; return true; } if (Parcelas == null || !Parcelas.Any()) { return false; } Parcela parcela = ((IEnumerable)Parcelas.OrderBy((Parcela x) => x.NumeroParcela)).FirstOrDefault((Func)((Parcela x) => !x.DataRecebimento.HasValue && (int)x.SubTipo == 1)); if (parcela != null && !IsFatura && SelectedDocumento.NumeroParcelas > 0m) { parcela.ValorLiquidoFatura = (SelectedDocumento.AdicionalComiss ? ((SelectedDocumento.PremioLiquido + SelectedDocumento.PremioAdicional) / SelectedDocumento.NumeroParcelas) : (SelectedDocumento.PremioLiquido / SelectedDocumento.NumeroParcelas)); } SelectedParcela = parcela ?? SelectedParcela; if (parcela == null) { await ShowMessage("NÃO HÁ MAIS NENHUMA PARCELA A SER BAIXADA"); } if (parcela != null) { SelectedParcela.Baixando = true; } return parcela != null; } public async Task SelecionaParcela(Parcela parcela) { SelectedParcela = parcela; if (parcela == null || ((DomainBase)parcela).Id == 0L || SelectedDocumento == null) { return; } if (Repasses == null) { await CarregaRepasse(((DomainBase)SelectedDocumento).Id); } List source = Repasses.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)parcela).Id).ToList(); if (IsFatura || (int)parcela.SubTipo != 1) { AllowEditVendedor = !parcela.DataRecebimento.HasValue && source.All((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)parcela).Id && !x.DataPagamento.HasValue); } if (!IsFatura && (int)parcela.SubTipo == 1) { AllowEditVendedor = parcela.NumeroParcela == 1 && !parcela.DataRecebimento.HasValue && source.All((VendedorParcela x) => (int)x.Parcela.SubTipo == 1 && !x.DataPagamento.HasValue); } Pagamentos = new ObservableCollection(source.OrderBy((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id)); } public async Task CarregaRepasse(long id) { Repasses = await VendedorServico.BuscaRepasse(id); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); } public async void CancelPagamento() { BaixarParcelas = false; SelectedParcela.Baixando = false; ObservableCollection observableCollection = await ParcelaServico.BuscarParcelasAsync(((DomainBase)SelectedDocumento).Id); Parcelas = (IsFatura ? new ObservableCollection(observableCollection.OrderByDescending((Parcela x) => x.NumeroParcela)) : observableCollection); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(Parcelas.FirstOrDefault()); } public void IncluirParcelaEspecial() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown SelectedParcela = new Parcela { IdEmpresa = SelectedDocumento.Controle.IdEmpresa, Documento = SelectedDocumento, Vencimento = Funcoes.GetNetworkTime().Date, Comissao = 100m, SubTipo = (SubTipo)3, NumeroParcela = 999, DataCriacao = Funcoes.GetNetworkTime(), UsuarioCriacao = ((DomainBase)Recursos.Usuario).Id }; Parcela parcelaAtual = Parcelas?.FirstOrDefault((Func)((Parcela x) => (int)x.SubTipo == 1)); if (parcelaAtual == null) { Repasses = new List(); return; } List list = Repasses.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)parcelaAtual).Id).ToList(); list.ForEach(delegate(VendedorParcela x) { ((DomainBase)x).Id = 0L; x.Parcela = SelectedParcela; x.DataPrePagamento = null; x.DataPagamento = null; x.ValorRepasse = default(decimal); x.DataPagamento = null; }); Repasses = list; RecalculaRepasse(); } public void IncluirFatura() { //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Expected O, but got Unknown Parcela? obj = ((IEnumerable)Parcelas.OrderBy((Parcela x) => x.NumeroParcela)).LastOrDefault((Func)((Parcela x) => (int)x.SubTipo == 1)); int numeroParcela = ((obj != null) ? obj.NumeroParcela : 0) + 1; decimal comissao = ((obj != null) ? obj.Comissao : 0m); Parcela selectedParcela = SelectedParcela; long num2; if (selectedParcela == null) { ObservableCollection parcelas = Parcelas; long? obj2; if (parcelas == null) { obj2 = null; } else { Parcela? obj3 = ((IEnumerable)parcelas.OrderBy((Parcela x) => x.NumeroParcela)).LastOrDefault((Func)((Parcela x) => (int)x.SubTipo == 1)); obj2 = ((obj3 != null) ? new long?(((DomainBase)obj3).Id) : null); } long? num = obj2; num2 = num.GetValueOrDefault(); } else { num2 = ((DomainBase)selectedParcela).Id; } long parcelaAtual = num2; DateTime networkTime = Funcoes.GetNetworkTime(); SelectedParcela = new Parcela { IdEmpresa = SelectedDocumento.Controle.IdEmpresa, Documento = SelectedDocumento, Vencimento = Funcoes.GetNetworkTime().Date, Comissao = comissao, SubTipo = (SubTipo)1, NumeroParcela = numeroParcela, DataCriacao = networkTime, UsuarioCriacao = ((DomainBase)Recursos.Usuario).Id }; if (parcelaAtual != 0L) { List list = Repasses.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == parcelaAtual).ToList(); list.ForEach(delegate(VendedorParcela x) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) ((DomainBase)x).Id = 0L; x.Parcela = SelectedParcela; x.DataPrePagamento = null; x.DataPagamento = null; x.PorcentagemRepasse = ((x.Repasse == null) ? 0m : ((SelectedDocumento.NegocioCorretora == (NegocioCorretora?)0) ? x.Repasse.ValorNovo : x.Repasse.ValorRenovacao)); }); Repasses = list; RecalculaRepasse(); } } public async Task ReplicarFatura() { if (Parcelas != null) { Parcela val = ((IEnumerable)Parcelas.OrderBy((Parcela x) => x.NumeroParcela)).LastOrDefault((Func)((Parcela x) => (int)x.SubTipo == 1)); if (val != null && val.NumeroParcela == 999) { await ShowMessage("PARCELA ESPECIAL NÃO PODE SER REPLICADA."); return; } int numeroParcela = ((val != null) ? val.NumeroParcela : 0) + 1; Parcela selectedParcela = SelectedParcela; decimal comissao = ((selectedParcela != null) ? selectedParcela.Comissao : 0m); Parcela parcelaAtual = Parcelas.First((Parcela x) => (int)x.SubTipo == 1); DateTime networkTime = Funcoes.GetNetworkTime(); Parcela obj = parcelaAtual; DateTime value = ((obj != null) ? obj.VigenciaFinal : null) ?? networkTime.Date; Parcela obj2 = parcelaAtual; DateTime value2 = ((obj2 == null) ? null : obj2.Emissao?.AddMonths(1)) ?? networkTime.Date; Parcela obj3 = parcelaAtual; DateTime vencimento = ((obj3 != null) ? obj3.Vencimento.AddMonths(1) : networkTime.Date); DateTime value3 = value.AddMonths(1); Parcela obj4 = parcelaAtual; decimal valor = ((obj4 != null) ? obj4.Valor : 0m); Parcela obj5 = parcelaAtual; decimal valorLiquidoFatura = ((obj5 != null) ? obj5.ValorLiquidoFatura : 0m); List list = Funcoes.DistinctBy(Repasses.Where((VendedorParcela x) => parcelaAtual != null && ((DomainBase)x.Parcela).Id == ((DomainBase)parcelaAtual).Id), (VendedorParcela x) => new { Id = ((DomainBase)x.Parcela).Id, vendedor = ((DomainBase)x.Vendedor).Id, tipovendedor = ((DomainBase)x.TipoVendedor).Id }).ToList(); SelectedParcela = new Parcela { IdEmpresa = SelectedDocumento.Controle.IdEmpresa, Documento = SelectedDocumento, Vencimento = vencimento, Comissao = comissao, SubTipo = (SubTipo)1, NumeroParcela = numeroParcela, VigenciaIncial = value, VigenciaFinal = value3, Valor = valor, Emissao = value2, DataCriacao = networkTime, ValorLiquidoFatura = valorLiquidoFatura }; list.ForEach(delegate(VendedorParcela x) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) ((DomainBase)x).Id = 0L; x.Parcela = SelectedParcela; x.DataPrePagamento = null; x.DataPagamento = null; x.PorcentagemRepasse = ((x.Repasse == null) ? 0m : ((SelectedDocumento.NegocioCorretora == (NegocioCorretora?)0) ? x.Repasse.ValorNovo : x.Repasse.ValorRenovacao)); }); Repasses = list; } RecalculaRepasse(); } public void IncluirVendedor() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown SelectedPagamento = new VendedorParcela { Documento = SelectedDocumento }; } public void SelecionarVendedor() { SelectedPagamento = Pagamentos?.FirstOrDefault(); } public void SelecionaPrimeiraParcela() { SelectedParcela = SelectedParcela ?? Parcelas.FirstOrDefault(); } public async Task IncluirApolice(bool renovar = false) { if (renovar && (string.IsNullOrWhiteSpace(SelectedDocumento.Apolice) || !SelectedDocumento.Emissao.HasValue)) { await ShowMessage("PROPOSTA NÃO PODE SER RENOVADA. NECESSÁRIO PREENCHER O NÚMERO DA APÓLICE E DATA DE EMISSÃO ANTES DE PROSSEGUIR."); return false; } List seguradoras = (from x in Recursos.Seguradoras where x.Ativo orderby x.Nome select x).ToList(); Seguradoras = seguradoras; SeguradorasAnteriores = Recursos.Seguradoras; List ramos = (from x in Recursos.Ramos where x.Ativo orderby x.Nome select x).ToList(); Ramos = ramos; List produtos = Recursos.Produtos.Where((Produto x) => x.Ativo).ToList(); Produtos = produtos; List status = Recursos.Status.Where((Status x) => x.Ativo).ToList(); Status = status; DateTime today = Funcoes.GetNetworkTime().Date; Documento documento; if (renovar) { SelectedDocumento = await Servico.BuscarApoliceAsync(((DomainBase)SelectedDocumento).Id); DocumentoRenovado = SelectedDocumento; if (Seguradoras.All((Seguradora x) => ((DomainBase)x).Id != ((DomainBase)SelectedDocumento.Controle.Seguradora).Id)) { Seguradoras.Add(SelectedDocumento.Controle.Seguradora); } if (SelectedDocumento.Controle.Produto != null && Produtos.All((Produto x) => ((DomainBase)x).Id != ((DomainBase)SelectedDocumento.Controle.Produto).Id)) { Seguradoras.Add(SelectedDocumento.Controle.Seguradora); } if (SelectedDocumento.Controle.Ramo != null && Ramos.All((Ramo x) => ((DomainBase)x).Id != ((DomainBase)SelectedDocumento.Controle.Ramo).Id)) { Seguradoras.Add(SelectedDocumento.Controle.Seguradora); } Vendedores = (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 20) ? TodosVendedores.Where((Vendedor x) => x.IdEmpresa == SelectedDocumento.Controle.IdEmpresa && x.Ativo && !x.Corretora).ToList() : new List()); Estipulantes = Recursos.Estipulantes.Where((Estipulante x) => x.IdEmpresa == SelectedDocumento.Controle.IdEmpresa && x.Ativo).ToList(); documento = new Documento { Controle = new Controle { Cliente = MainViewModel.ClienteSelecionado, IdEmpresa = SelectedDocumento.Controle.IdEmpresa, Ramo = SelectedDocumento.Controle.Ramo, Seguradora = SelectedDocumento.Controle.Seguradora, SeguradoraAnterior = SelectedDocumento.Controle.Seguradora }, Ordem = 0, Tipo = 0, NegocioCorretora = (NegocioCorretora)1, Situacao = (TipoSeguro)2, Negocio = (Negocio)1, TipoRecebimento = (TipoRecebimento)1, Vigencia1 = SelectedDocumento.Vigencia2.GetValueOrDefault(today), Vigencia2 = (SelectedDocumento.Vigencia2?.AddYears(1) ?? today.AddYears(1)), ApoliceConferida = false, PropostaAssinada = false, AdicionalComiss = false, Excluido = false, ApoliceAnterior = SelectedDocumento.Apolice, FormaPagamento = null }; EmissaoDocumento = today; TransmissaoDocumento = today; if (await ShowMessage("DESEJA MANTER OS VENDEDORES DA APÓLICE ANTERIOR?", "SIM", "NÃO")) { Pagamentos?.ToList().ForEach(delegate(VendedorParcela x) { x.Documento = null; x.ValorRepasse = default(decimal); x.ValorTotal = null; x.DataPagamento = null; x.DataPagamento = null; }); } else { Pagamentos = new ObservableCollection { PropriaCorretora() }; Repasses = null; } Pagamentos = ((Pagamentos != null) ? new ObservableCollection(Pagamentos) : new ObservableCollection()); } else { Inclusao = true; Vendedores = (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 20) ? TodosVendedores.Where((Vendedor x) => x.IdEmpresa == MainViewModel.ClienteSelecionado.IdEmpresa && x.Ativo && !x.Corretora).ToList() : new List()); Estipulantes = Recursos.Estipulantes.Where((Estipulante x) => x.IdEmpresa == MainViewModel.ClienteSelecionado.IdEmpresa && x.Ativo).ToList(); documento = new Documento { Controle = new Controle { Cliente = MainViewModel.ClienteSelecionado, IdEmpresa = MainViewModel.ClienteSelecionado.IdEmpresa }, Ordem = 0, Tipo = 0, NegocioCorretora = (NegocioCorretora)0, Situacao = (TipoSeguro)1, TipoRecebimento = (TipoRecebimento)1, Vigencia1 = today, Vigencia2 = today.AddYears(1), ApoliceConferida = false, PropostaAssinada = false, AdicionalComiss = false, Excluido = false, FormaPagamento = null }; Pagamentos = null; Repasses = null; } IsFatura = false; SelectedParcela = null; SelectedDocumento = null; SelectedPagamento = null; Parcelas = null; SelectedDocumento = documento; IsEndosso = false; NovaApolice = true; Renovar = renovar; EnableAlterarSituacao = true; AllowEditVendedor = !renovar; AllowEditApolice = true; base.IsEnabledEdit = true; base.IsEnabledEditEndosso = true; base.AllowEditParcela = false; base.EnableFields = true; base.EnableIncluir = false; Gestor.Application.Actions.Actions.EnableMainMenu?.Invoke(obj: false); return true; } public async Task VerificarVigencia(Documento documento) { if (!documento.Vigencia2.HasValue) { return true; } TimeSpan timeSpan = DateTime.Parse(documento.Vigencia2.ToString()) - documento.Vigencia1; string text = ((timeSpan.Days > 366) ? "VIGÊNCIA FINAL MAIOR QUE 365 DIAS.\nDESEJA CONTINUAR?" : ((timeSpan.Days < 365) ? "VIGÊNCIA FINAL MENOR QUE 365 DIAS.\nDESEJA CONTINUAR?" : "")); if (text == "") { return true; } return await ShowMessage(text, "SIM", "NÃO"); } private void ZerarValores() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 if ((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) { SelectedDocumento.PremioLiquido = 0m; SelectedDocumento.PremioAdicional = 0m; SelectedDocumento.PremioAdicional = 0m; SelectedDocumento.Iof = 0m; SelectedDocumento.Diferenca = 0m; SelectedDocumento.NumeroParcelas = 0m; } } public async Task>> Salvar(bool critica = false) { if ((int)SelectedDocumento.Situacao == 2) { SelectedDocumento.Negocio = (Negocio)((SelectedDocumento.NegocioCorretora != (NegocioCorretora?)0) ? 1 : 2); } Status status = SelectedDocumento.Status; if (status != null && ((DomainBase)status).Id == 0) { SelectedDocumento.Status = null; } ZerarValores(); List> errors = SelectedDocumento.Validate(IsEndosso, Recursos.Configuracoes.Any((ConfiguracaoSistema c) => (int)c.Configuracao == 11)); if (SelectedDocumento.Comissao > 100m) { SelectedDocumento.Comissao = 100m; } bool insert = ((DomainBase)SelectedDocumento).Id == 0; VendedorParcela selectedPagamento = SelectedPagamento; if (((selectedPagamento != null) ? selectedPagamento.Vendedor : null) != null && SelectedDocumento.Vendedores == null) { SelectedDocumento.Vendedores = new List { TodosVendedores.First((Vendedor x) => x.Corretora && x.IdEmpresa == SelectedDocumento.Controle.IdEmpresa) }; } if (insert) { VendedorParcela selectedPagamento2 = SelectedPagamento; if (((selectedPagamento2 != null) ? selectedPagamento2.Vendedor : null) != null && SelectedDocumento.Vendedores != null) { List> list = errors; list.AddRange((await AdicionarVendedor()) ?? new List>()); } } if (errors.Count > 0) { return errors; } bool flag = SelectedDocumento.Tipo == 0; if (flag) { flag = !(await VerificarVigencia(SelectedDocumento)); } if (flag) { if (critica) { errors.Add(new KeyValuePair("Vigencia2", "VIGENCIANAOACEITA")); } return errors; } if ((int)SelectedDocumento.TipoEndosso.GetValueOrDefault() != 3 && (int)SelectedDocumento.Situacao == 3 && ((DomainBase)SelectedDocumento).Id == 0L) { await ShowMessage("EM DOCUMENTOS CANCELADOS SÓ É POSSIVEL INCLUIR ENDOSSO DE REABILITAÇÃO."); Alterar(alterar: true); return null; } if (SelectedDocumento.TipoEndosso.HasValue && (int)SelectedDocumento.TipoEndosso.GetValueOrDefault() == 3) { SelectedDocumento.Situacao = (TipoSeguro)4; } Documento documento = SelectedDocumento; Alterar(alterar: false); if (!documento.FormaPagamento.HasValue) { documento.FormaPagamento = (FormaPagamento)(Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 21) ? 4 : 0); } Acesso = (AcessoApolice)0; bool updateValores = ((DomainBase)documento).Id > 0 && AllowEditApolice && (CancelDocumento.PremioLiquido != documento.PremioLiquido || CancelDocumento.AdicionalComiss != documento.AdicionalComiss || (documento.AdicionalComiss && CancelDocumento.PremioAdicional != documento.PremioAdicional) || CancelDocumento.Comissao != documento.Comissao || CancelDocumento.NegocioCorretora != documento.NegocioCorretora || CancelDocumento.Diferenca != documento.Diferenca || CancelDocumento.Iof != documento.Iof || UpdatePremio); bool criarNovasParelas = (int)documento.TipoRecebimento.GetValueOrDefault() != 2 && (((DomainBase)documento).Id == 0L || CancelDocumento.NumeroParcelas != documento.NumeroParcelas || documento.NumeroParcelas != (decimal)Parcelas.Count((Parcela x) => (int)x.SubTipo == 1)); bool renovacao = (int)documento.NegocioCorretora.GetValueOrDefault() == 1; if (criarNovasParelas && (int)documento.TipoRecebimento.GetValueOrDefault() == 1) { CriarParcelas(insert); Parcelas.ToList().ForEach(delegate(Parcela x) { x.Documento = documento; errors.AddRange(x.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 9), Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 11), EditandoParcela, Recursos.Configuracoes.Any((ConfiguracaoSistema r) => (int)r.Configuracao == 16))); }); if (errors.Count > 0) { Alterar(alterar: true); return errors.Distinct().ToList(); } } if (Parcelas == null || Parcelas.Count == 0) { Pagamentos = new ObservableCollection(); } if (updateValores && !criarNovasParelas) { AtualizaValores(renovacao); } if ((int)SelectedDocumento.Situacao == 5 && SelectedDocumento.Controle.Documentos != null && SelectedDocumento.Controle.Documentos.Count > 0) { foreach (Documento item in SelectedDocumento.Controle.Documentos.Where((Documento x) => x.Tipo != 0 && !x.Excluido)) { if ((int)item.Situacao != 3) { item.SituacaoAnterior = item.Situacao; item.Situacao = (TipoSeguro)5; await Servico.Save(item, updateParcelas: false, criarParcelas: false); } } } if (((DomainBase)SelectedDocumento).Id != 0L && SelectedDocumento.Tipo == 0 && SelectedDocumento.Controle.Documentos != null && SelectedDocumento.Controle.Documentos.Count > 0 && SelectedDocumento.Controle.Documentos.Where((Documento x) => x.Tipo != 0 && !x.Excluido).Any((Documento x) => x.Apolice != SelectedDocumento.Apolice || x.Proposta != SelectedDocumento.Proposta)) { foreach (Documento item2 in SelectedDocumento.Controle.Documentos.Where((Documento x) => x.Tipo != 0 && !x.Excluido)) { item2.Apolice = SelectedDocumento.Apolice; item2.Proposta = SelectedDocumento.Proposta; await Servico.Save(item2, updateParcelas: false, criarParcelas: false); ToggleSnackBar("NUMERO DA PROPOSTA/APOLICE ATUALIZADOS NO ENDOSSO"); } } if (Renovar) { if (!CancelDocumento.NegocioCorretora.HasValue) { CancelDocumento.NegocioCorretora = (NegocioCorretora)((CancelDocumento.Negocio.HasValue && (int)CancelDocumento.Negocio.GetValueOrDefault() == 1) ? 1 : 0); } CancelDocumento.Situacao = (TipoSeguro)5; IEnumerable enumerable = CancelDocumento.Controle.Documentos.Where((Documento d) => d.Tipo == 1 && ((int)d.Situacao == 1 || (int)d.Situacao == 2 || (int)d.Situacao == 4)); foreach (Documento item3 in enumerable) { item3.Situacao = (TipoSeguro)5; await Servico.Save(item3, updateParcelas: false, criarParcelas: false); } Servico.Sucesso = true; await Servico.Save(CancelDocumento, updateParcelas: false, criarParcelas: false); if (!Servico.Sucesso) { await ShowMessage("NÃO FOI POSSÍVEL ALTERAR O STATUS DO DOCUMENTO RENOVADO, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO."); } string text = (string.IsNullOrEmpty(CancelDocumento.Apolice) ? ("A PROPOSTA \"" + CancelDocumento.Proposta + "\"") : ("A APÓLICE \"" + CancelDocumento.Apolice + "\"")); RegistrarAcao("RENOVOU " + text, ((DomainBase)CancelDocumento).Id, (TipoTela)2, GerarObs(CancelDocumento)); } if (documento.TipoEndosso.HasValue && (int)documento.TipoEndosso.GetValueOrDefault() == 4 && SelectedDocumento.Vigencia2.HasValue && !(await Servico.Prorrogar(((DomainBase)SelectedDocumento.Controle).Id, SelectedDocumento.Vigencia2.Value))) { await ShowMessage("NÃO FOI POSSÍVEL ALTERAR A VIGÊNCIA FINAL DA APÓLICE, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO."); } if (documento.TipoEndosso.HasValue && (int)documento.TipoEndosso.GetValueOrDefault() == 3 && !(await Servico.Reabilitar(((DomainBase)SelectedDocumento.Controle).Id))) { await ShowMessage("NÃO FOI POSSÍVEL ALTERAR O STATUS DA APÓLICE, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO."); } if (documento.TipoEndosso.HasValue && (int)documento.TipoEndosso.GetValueOrDefault() == 2) { Documento apolice = ((IEnumerable)CancelDocumento.Controle.Documentos).FirstOrDefault((Func)((Documento x) => x.Tipo == 0)); apolice.Situacao = (TipoSeguro)3; IEnumerable enumerable2 = CancelDocumento.Controle.Documentos.Where((Documento x) => x.Tipo == 1); foreach (Documento item4 in enumerable2) { item4.Situacao = (TipoSeguro)3; await Servico.Save(item4, updateParcelas: false, criarParcelas: false); } if (!apolice.NegocioCorretora.HasValue) { apolice.NegocioCorretora = (NegocioCorretora)((apolice.Negocio.HasValue && (int)apolice.Negocio.GetValueOrDefault() == 1) ? 1 : 0); } documento.Situacao = (TipoSeguro)3; Servico.Sucesso = true; await Servico.Save(apolice, updateParcelas: false, criarParcelas: false); if (!Servico.Sucesso) { await ShowMessage("NÃO FOI POSSÍVEL ALTERAR O STATUS DO DOCUMENTO CANCELADO, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO."); } flag = insert; if (flag) { flag = await ShowMessage("DESEJA BAIXAR AS PARCELAS PENDENTES ABAIXO DESSE DOCUMENTO?", "SIM", "NÃO"); } if (flag) { bool baixarParcelas = true; foreach (Documento documento2 in apolice.Controle.Documentos) { baixarParcelas = await Servico.BaixarParcelasCancelamento(documento2, estorno: false) && baixarParcelas; } if (!baixarParcelas) { await ShowMessage("NÃO FOI POSSÍVEL AS PARCELAS DO DOCUMENTO CANCELADO, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO."); } } string text2 = "A APÓLICE \"" + apolice.Apolice + "\""; RegistrarAcao("CANCELOU " + text2, ((DomainBase)apolice).Id, (TipoTela)2, GerarObs(apolice)); } if (Parcelas != null) { documento.Parcelas = new ObservableCollection(Parcelas.Where((Parcela x) => (int)x.SubTipo == 1)); } if (!string.IsNullOrWhiteSpace(Anotacoes)) { documento.Observacao = $"{Recursos.Usuario.Nome}, ID: {((DomainBase)Recursos.Usuario).Id}, {Funcoes.GetNetworkTime():g}{Environment.NewLine}{Anotacoes}{Environment.NewLine}{Environment.NewLine}{documento.Observacao}"; } Documento documentoSelecionado = DocumentoSelecionado; int num; if (documentoSelecionado == null) { num = 0; } else { _ = documentoSelecionado.Situacao; num = 1; } if (num != 0 && (int)DocumentoSelecionado.Situacao == 7 && DocumentoSelecionado.Situacao != documento.Situacao) { ObservableCollection parcelas = documento.Parcelas; if (parcelas != null && parcelas.Where((Parcela x) => x.DataRecebimento.HasValue).Count() >= 1) { await ShowMessage("O DOCUMENTO TEM PARCELAS BAIXADAS DEVIDO A RECUSA. CASO NECESSÁRIO, REALIZE A EXCLUSÃO DAS BAIXAS MANUALMENTE."); Alterar(alterar: true); return null; } } Servico.Sucesso = true; if (((DomainBase)documento).Id == 0L) { documento.DataCriacao = Funcoes.GetNetworkTime(); documento.UsuarioCriacao = Recursos.Usuario; } documento.SituacaoAnterior = documento.Situacao; Documento documentoSalvo = await Servico.Save(documento, updateValores, criarNovasParelas); List list2 = Pagamentos?.Where((VendedorParcela p) => (int)documentoSalvo.TipoRecebimento.GetValueOrDefault() == 1 && p.Repasse != null && ((int)p.Repasse.Base.GetValueOrDefault() == 1 || (int)p.Repasse.Base.GetValueOrDefault() == 4 || (int)p.Repasse.Base.GetValueOrDefault() == 5) && !p.DataPagamento.HasValue).ToList(); if (list2 != null && list2.Count > 0) { List atualizarPagamentos = new List(); list2?.ForEach(delegate(VendedorParcela p) { //IL_001a: 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) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected I4, but got Unknown BaseRepasse? @base = p.Repasse.Base; if (@base.HasValue) { BaseRepasse valueOrDefault = @base.GetValueOrDefault(); switch (valueOrDefault - 1) { case 0: if (!(p.DataPrePagamento == documentoSalvo.Vigencia1)) { p.DataPrePagamento = documentoSalvo.Vigencia1; atualizarPagamentos.Add(p); } break; case 3: if (!(p.DataPrePagamento == documentoSalvo.Emissao)) { p.DataPrePagamento = documentoSalvo.Emissao; atualizarPagamentos.Add(p); } break; case 4: if (!(p.DataPrePagamento == documentoSalvo.Remessa)) { p.DataPrePagamento = documentoSalvo.Remessa; atualizarPagamentos.Add(p); } break; case 1: case 2: break; } } }); if (atualizarPagamentos.Count > 0) { await new ParcelaServico().SaveRange(atualizarPagamentos.ToList()); } } if (!Servico.Sucesso) { Alterar(alterar: true); return null; } Documento documentoSelecionado2 = DocumentoSelecionado; int num2; if (documentoSelecionado2 == null) { num2 = 0; } else { _ = documentoSelecionado2.Situacao; num2 = 1; } if (num2 != 0 && (int)DocumentoSelecionado.Situacao == 7 && documento.Situacao != DocumentoSelecionado.Situacao) { Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)21, ""); } SelectedDocumento = await Servico.BuscarApoliceAsync(((DomainBase)documentoSalvo).Id); ((DomainBase)SelectedDocumento).Initialize(); await CarregarParcelas(SelectedDocumento); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); SelectedParcela = Parcelas.FirstOrDefault(); Documento selectedDocumento = SelectedDocumento; VendedorParcela? obj = ((IEnumerable)Repasses).FirstOrDefault((Func)((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id == 1)); selectedDocumento.VendedorPrincipal = ((obj != null) ? obj.Vendedor : null); bool renovar = Renovar; ConsultaViewModel.DocumentoRenovado = (renovar ? DocumentoRenovado : ConsultaViewModel.DocumentoSelecionado); NovaApolice = false; Renovar = false; if (insert) { AllowEditApolice = true; base.IsEnabledEdit = true; base.IsEnabledEditEndosso = true; if (Invoke) { ConsultaViewModel.DocumentoSelecionado = SelectedDocumento; } if (Invoke) { Gestor.Application.Actions.Actions.RecarregarDocumentos?.Invoke(SelectedDocumento); } if (Invoke) { Gestor.Application.Actions.Actions.UpdateDocumento?.Invoke(SelectedDocumento); } } else if (Invoke) { long id = ((DomainBase)SelectedDocumento).Id; Documento documentoSelecionado3 = ConsultaViewModel.DocumentoSelecionado; if (id != ((documentoSelecionado3 != null) ? new long?(((DomainBase)documentoSelecionado3).Id) : null)) { ConsultaViewModel.DocumentoSelecionado = SelectedDocumento; } } if (Parcelas.Count == 0) { AllowEditVendedor = false; } base.AllowEditParcela = true; ToggleSnackBar("DOCUMENTO SALVO COM SUCESSO"); Gestor.Application.Actions.Actions.EnableMainMenu?.Invoke(obj: true); Gestor.Application.Actions.Actions.EnableMenu?.Invoke(obj: true); if (renovar && await ShowMessage("DESEJA MANTER OS DADOS DO PERFIL DA APÓLICE ANTERIOR?", "SIM", "NÃO")) { List source = await PerfilServico.BuscarPerfis(((DomainBase)CancelDocumento.Controle).Id); try { foreach (Perfil item5 in source.ToList()) { Perfil perfil = new Perfil { Id = 0L, AntiFurto = item5.AntiFurto, CepCirculacao = ValidationHelper.FormataCep(item5.CepCirculacao), CepPernoite = ValidationHelper.FormataCep(item5.CepPernoite), Cliente = item5.Cliente, Controle = new Controle { AssistenciaId = item5.Controle.AssistenciaId, Cliente = item5.Controle.Cliente, Documentos = item5.Controle.Documentos, Id = ((DomainBase)SelectedDocumento.Controle).Id, IdEmpresa = item5.Controle.IdEmpresa, Item = item5.Controle.Item, Produto = item5.Controle.Produto, Ramo = item5.Controle.Ramo, Seguradora = item5.Controle.Seguradora, SeguradoraAnterior = item5.Controle.SeguradoraAnterior }, Cpf = item5.Cpf, DistanciaResidenciaTrabalho = item5.DistanciaResidenciaTrabalho, EstadoCivil = item5.EstadoCivil, EstenderCobertura = item5.EstenderCobertura, GaragemEstudo = item5.GaragemEstudo, GaragemResidencia = item5.GaragemResidencia, GaragemTrabalho = item5.GaragemTrabalho, Habilitacao = item5.Habilitacao, Isencao = item5.Isencao, KmMensal = item5.KmMensal, Nascimento = item5.Nascimento, Nome = item5.Nome, Ocupacao = item5.Ocupacao, Relacao = item5.Relacao, SeguroVida = item5.SeguroVida, Sexo = item5.Sexo, TempoHabilitacao = item5.TempoHabilitacao, TipoResidencia = item5.TipoResidencia, UsoDependentes = item5.UsoDependentes, UsoProfissional = item5.UsoProfissional, VeiculoResidencia = item5.VeiculoResidencia }; await PerfilServico.Save(perfil); } } catch (Exception ex) { _ = ex; await ShowMessage("NÃO FOI POSSÍVEL MANTER OS DADOS DO PERFIL DA APÓLICE ANTERIOR, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO."); } } CancelDocumento = (Documento)((DomainBase)SelectedDocumento).Clone(); EditarParcelasLabel = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? "EDITAR FATURAS" : "EDITAR PARCELAS"); base.EnableFields = false; CalculaComissao(SelectedDocumento, Parcelas); string text3 = (insert ? "INCLUIU" : "ALTEROU"); string text4 = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("A PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("A APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("A PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("O ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); RegistrarAcao(text3 + " " + text4, ((DomainBase)SelectedDocumento).Id, (TipoTela)2, GerarObs(SelectedDocumento)); if ((renovar || (IsEndosso && (int)SelectedDocumento.TipoEndosso.GetValueOrDefault() != 2)) && insert) { Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)3, renovar ? "Renovação" : "Endosso"); return null; } if ((int)SelectedDocumento.TipoEndosso.GetValueOrDefault() == 2) { return null; } flag = !Invoke || !insert; if (!flag) { flag = !(await ShowMessage("DESEJA INCLUIR O ITEM AGORA?", "SIM", "NÃO")); } if (flag) { return null; } Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)3, ""); return null; } private void AtualizaValores(bool renovacao) { Repasses.ForEach(delegate(VendedorParcela x) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Invalid comparison between Unknown and I4 if (x.Repasse != null && (int)x.Repasse.Tipo.GetValueOrDefault() != 1) { Parcela parcela = x.Parcela; if ((int)parcela.SubTipo == 1) { parcela.Documento = SelectedDocumento; decimal value = Funcoes.CalculaRepasse(x.Repasse, parcela); decimal value2 = (renovacao ? x.Repasse.ValorRenovacao : x.Repasse.ValorNovo); if (x.CoCorretagem) { value2 = x.Repasse.ValorNovo; } if ((int)x.Repasse.Forma.GetValueOrDefault() == 3) { value /= SelectedDocumento.NumeroParcelas; } if (x.CoCorretagem) { decimal comissao = SelectedDocumento.Comissao; Documento selectedDocumento = SelectedDocumento; decimal valueOrDefault = ((selectedDocumento != null) ? selectedDocumento.ComissaoTotal : null).GetValueOrDefault(); value = SelectedDocumento.PremioLiquido * ((valueOrDefault - comissao) / 100m); } x.PorcentagemRepasse = value2; x.ValorRepasse = value; x.ValorTotal = value; } } }); decimal valor = ((Parcelas.Count((Parcela x) => (int)x.SubTipo == 1) > 0) ? (SelectedDocumento.PremioTotal / (decimal)Parcelas.Count((Parcela x) => (int)x.SubTipo == 1)) : 0m); Parcelas.Where((Parcela x) => (int)x.SubTipo == 1).ToList().ForEach(delegate(Parcela x) { x.Valor = valor; x.Comissao = SelectedDocumento.Comissao; x.Vendedores = new ObservableCollection(Repasses.Where((VendedorParcela r) => ((DomainBase)r.Parcela).Id == ((DomainBase)x).Id)); }); } private void CriarParcelas(bool insert) { if (Repasses == null) { Repasses = new List(); } var list = (from x in Repasses where insert || (int)x.Parcela.SubTipo == 1 group x by new { x.Repasse, x.TipoVendedor }).Distinct().ToList(); List vendedorParcelas = new List(); list.ForEach(x => { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 if (x.Key.Repasse != null) { VendedorParcela val = CalculaRepasse(x.Key.Repasse, x.Key.TipoVendedor); if ((int)val.Repasse.Forma.GetValueOrDefault() == 3) { val.ValorRepasse /= (decimal?)((SelectedDocumento.NumeroParcelas > 0m) ? SelectedDocumento.NumeroParcelas : 1m); } vendedorParcelas.Add(val); } }); if (vendedorParcelas.All((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id != 1)) { vendedorParcelas.Add(PropriaCorretora()); } Parcelas = new ObservableCollection(CriarParcelas(vendedorParcelas)); } private List CriarParcelas(List vendedores) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Invalid comparison between Unknown and I4 //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Expected O, but got Unknown //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Invalid comparison between Unknown and I4 //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Invalid comparison between Unknown and I4 List list = new List(); if (SelectedDocumento.NumeroParcelas == 0m) { return list; } decimal valor = SelectedDocumento.PremioTotal / SelectedDocumento.NumeroParcelas; if (!SelectedDocumento.FormaPagamento.HasValue) { SelectedDocumento.FormaPagamento = (FormaPagamento)0; } for (int i = 1; (decimal)i <= SelectedDocumento.NumeroParcelas; i++) { Parcela item = new Parcela { IdEmpresa = SelectedDocumento.Controle.IdEmpresa, NumeroParcela = i, Valor = valor, Comissao = SelectedDocumento.Comissao, Vencimento = SelectedDocumento.Vigencia1.AddMonths(i - 1), SubTipo = (SubTipo)1, Vendedores = new ObservableCollection((i == 1) ? vendedores : vendedores.Where(delegate(VendedorParcela x) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 Repasse repasse = x.Repasse; return repasse != null && (int)repasse.Forma.GetValueOrDefault() == 3; }).ToList()), TipoPagamento = (TipoPagamento)((SelectedDocumento.FormaPagamento == (FormaPagamento?)0) ? 7 : (((int)SelectedDocumento.FormaPagamento.GetValueOrDefault() == 1) ? 3 : (((int)SelectedDocumento.FormaPagamento.GetValueOrDefault() == 2) ? 15 : (((int)SelectedDocumento.FormaPagamento.GetValueOrDefault() == 3 && i == 1) ? 15 : 7)))), DataCriacao = Funcoes.GetNetworkTime(), UsuarioCriacao = ((DomainBase)Recursos.Usuario).Id }; list.Add(item); } return list; } private List CriarRepasses(VendedorParcela repasse) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Invalid comparison between Unknown and I4 if (Parcelas == null || Parcelas.Count == 0 || SelectedDocumento == null) { return null; } List repasses = new List(); repasse.ValorRepasse = (((int)repasse.Repasse.Forma.GetValueOrDefault() != 3) ? repasse.ValorRepasse : (repasse.ValorRepasse / (decimal?)SelectedDocumento.NumeroParcelas)); Parcelas.ToList().ForEach(delegate(Parcela x) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 if ((int)repasse.Repasse.Forma.GetValueOrDefault() == 3 || x.NumeroParcela <= 1) { VendedorParcela val = (VendedorParcela)((DomainBase)repasse).Clone(); if ((int)repasse.Repasse.Forma.GetValueOrDefault() == 3) { val.DataPrePagamento = x.Vencimento; } val.Parcela = x; repasses.Add(val); } }); return repasses; } private VendedorParcela PropriaCorretora() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown return new VendedorParcela { Repasse = null, ValorRepasse = default(decimal), Documento = SelectedDocumento, Vendedor = ((IEnumerable)Recursos.Vendedores).FirstOrDefault((Func)delegate(Vendedor x) { long idEmpresa = x.IdEmpresa; Documento selectedDocumento = SelectedDocumento; long? obj; if (selectedDocumento == null) { obj = null; } else { Controle controle = selectedDocumento.Controle; obj = ((controle != null) ? new long?(controle.IdEmpresa) : null); } return idEmpresa == (obj ?? ((DomainBase)Recursos.Empresa).Id) && x.Corretora; }), PorcentagemRepasse = default(decimal), TipoVendedor = Recursos.TipoVendedor.First((TipoVendedor x) => ((DomainBase)x).Id == 1) }; } public VendedorParcela CalculaRepasse(Repasse repasse, TipoVendedor tipoVendedor) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Invalid comparison between Unknown and I4 //IL_00d7: Expected O, but got Unknown bool flag = (int)SelectedDocumento.NegocioCorretora.GetValueOrDefault() == 1; if (SelectedParcela == null) { SelectedParcela = new Parcela { SubTipo = (SubTipo)1, IdEmpresa = SelectedDocumento.Controle.IdEmpresa }; } SelectedParcela.Documento = SelectedDocumento; decimal value = Funcoes.CalculaRepasse(repasse, SelectedParcela); return new VendedorParcela { Repasse = repasse, ValorRepasse = value, ValorTotal = value, Vendedor = repasse.Vendedor, PorcentagemRepasse = (flag ? repasse.ValorRenovacao : repasse.ValorNovo), TipoVendedor = tipoVendedor, CoCorretagem = (repasse != null && (int)repasse.Tipo.GetValueOrDefault() == 3) }; } public List GetRepasses(Vendedor vendedor) { if (CoCorretagem) { return RepassesVendedores.Where((Repasse x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)vendedor).Id)?.Where((Repasse x) => (int)x.Tipo.GetValueOrDefault() == 3)?.OrderBy((Repasse x) => x.ValorNovo).ToList(); } if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 20)) { return (from x in RepassesVendedores.Where((Repasse x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)vendedor).Id)?.Where((Repasse x) => (int)x.Tipo.GetValueOrDefault() != 3) orderby x.ValorNovo select x).ToList(); } if (RepassesVendedores.Any((Repasse x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)vendedor).Id && x.Ramo != null && ((DomainBase)x.Ramo).Id == ((DomainBase)SelectedDocumento.Controle.Ramo).Id)) { return (from x in RepassesVendedores where ((DomainBase)x.Vendedor).Id == ((DomainBase)vendedor).Id && x.Ramo != null && ((DomainBase)x.Ramo).Id == ((DomainBase)SelectedDocumento.Controle.Ramo).Id orderby x.ValorNovo select x).ToList(); } return (from x in RepassesVendedores where ((DomainBase)x.Vendedor).Id == ((DomainBase)vendedor).Id && x.Ramo == null orderby x.ValorNovo select x).ToList(); } public void FiltrarRepasse(Vendedor vendedor) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown if (SelectedPagamento == null) { SelectedPagamento = new VendedorParcela(); } SelectedPagamento.Vendedor = vendedor; RepassesVendedor = GetRepasses(vendedor); } public async Task>> AdicionarVendedor() { if (SelectedPagamento == null) { return null; } if (SelectedPagamento.Repasse == null) { return new List> { new KeyValuePair("ValorRepasse|VALOR DO REPASSE", "OBRIGATÓRIO") }; } if (SelectedDocumento.Comissao == 0m) { return new List> { new KeyValuePair("Comissao|PORCENTAGEM DE COMISSÃO", "OBRIGATÓRIO") }; } Loading(isLoading: true); SelectedPagamento.Parcela = SelectedParcela ?? Parcelas?.OrderBy((Parcela x) => x.NumeroParcela).FirstOrDefault(); List vinculo = SelectedPagamento.Repasse.Vinculo?.Where((VinculoRepasse x) => ((DomainBase)x.TipoVendedor).Id == ((DomainBase)SelectedPagamento.TipoVendedor).Id).ToList(); List pagamentos = new List { SelectedPagamento }; bool renovacao = (SelectedDocumento.NegocioCorretora.HasValue ? ((int)SelectedDocumento.NegocioCorretora.GetValueOrDefault() == 1) : ((int)SelectedDocumento.Situacao == 2 && SelectedDocumento.Negocio.HasValue && (int)SelectedDocumento.Negocio.GetValueOrDefault() == 1)); if (vinculo != null && vinculo.Count > 0 && await ShowMessage("DESEJA ADICIONAR OS REPASSES VINCULADOS?", "SIM", "NÃO")) { foreach (VinculoRepasse item2 in vinculo) { decimal value = Funcoes.CalculaRepasse(item2.RepasseVinculo, SelectedPagamento.Parcela, SelectedPagamento.Parcela == null || (int)SelectedPagamento.Parcela.SubTipo == 1); VendedorParcela val = new VendedorParcela { TipoVendedor = item2.TipoVendedorVinculo, Vendedor = item2.RepasseVinculo.Vendedor, Repasse = item2.RepasseVinculo, Documento = SelectedPagamento.Documento, Parcela = SelectedPagamento.Parcela, PorcentagemRepasse = (renovacao ? item2.RepasseVinculo.ValorRenovacao : item2.RepasseVinculo.ValorNovo), ValorRepasse = value, ValorTotal = value }; Repasse repasseVinculo = item2.RepasseVinculo; val.CoCorretagem = repasseVinculo != null && (int)repasseVinculo.Tipo.GetValueOrDefault() == 3; VendedorParcela item = val; pagamentos.Add(item); } } List> errors; foreach (VendedorParcela p in pagamentos) { VendedorParcela pagamento = p; if (((pagamento != null) ? pagamento.Documento : null) == null && ((DomainBase)pagamento.Parcela.Documento).Id == ((DomainBase)SelectedDocumento).Id) { pagamento.Documento = SelectedDocumento; } errors = pagamento.Validate(); errors.AddRange(Validate(pagamento)); if (errors.Count > 0) { if (SelectedPagamento == null) { SelectedPagamento = pagamento; } Loading(isLoading: false); return errors; } if (pagamento.Repasse != null) { switch (pagamento.Repasse.Base) { case 2L: pagamento.DataPrePagamento = ((pagamento.Parcela.Vencimento == DateTime.MinValue) ? SelectedDocumento.Vigencia1 : pagamento.Parcela.Vencimento); break; case 0L: pagamento.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? SelectedParcela.VigenciaIncial : new DateTime?(SelectedDocumento.Vigencia1)); break; case 1L: pagamento.DataPrePagamento = SelectedDocumento.DataCriacao; break; case 3L: pagamento.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? SelectedParcela.Emissao : SelectedDocumento.Emissao); break; case 4L: pagamento.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? SelectedParcela.Emissao : SelectedDocumento.Remessa); break; } } if (Pagamentos == null) { Pagamentos = new ObservableCollection(); } if (((DomainBase)SelectedDocumento).Id == 0L) { Repasses.Add(pagamento); Pagamentos.Add(pagamento); SelectedPagamento = new VendedorParcela(); continue; } if ((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() != 2 && SelectedDocumento.NumeroParcelas != (decimal)Parcelas.Count((Parcela x) => (int)x.SubTipo == 1)) { CriarParcelas(insert: true); Parcelas.ToList().ForEach(delegate(Parcela x) { x.Documento = SelectedDocumento; errors.AddRange(x.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 9), Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 11), EditandoParcela, Recursos.Configuracoes.Any((ConfiguracaoSistema r) => (int)r.Configuracao == 16))); }); if (errors.Count > 0) { Loading(isLoading: false); return errors.Distinct().ToList(); } ParcelaServico.Sucesso = true; await ParcelaServico.SaveRange(Parcelas.ToList()); if (!ParcelaServico.Sucesso) { Repasses = await VendedorServico.BuscaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); SelectedPagamento = null; Loading(isLoading: false); return null; } await CarregarParcelas(SelectedDocumento); SelectedPagamento.Parcela = Parcelas.First(); SelectedParcela = Parcelas.First(); } VendedorParcela corretora = ((IEnumerable)Repasses).FirstOrDefault((Func)((VendedorParcela x) => (int)x.Parcela.SubTipo == 1 && ((DomainBase)x.TipoVendedor).Id == 1 && x.Vendedor.Corretora)); bool excluirCorretora = !pagamento.CoCorretagem && ((DomainBase)pagamento.TipoVendedor).Id == 1 && corretora != null; if (pagamento.CoCorretagem) { await AjusteComissãoCoCorretagem(); decimal premioLiquido = SelectedDocumento.PremioLiquido; decimal? num = (SelectedDocumento.ComissaoTotal - (decimal?)SelectedDocumento.Comissao) / (decimal?)100; decimal? num2 = (decimal?)premioLiquido * num; pagamento.PorcentagemRepasse = p.Repasse.ValorNovo; pagamento.ValorRepasse = num2; pagamento.ValorTotal = num2; p.ValorRepasse = num2; p.ValorTotal = num2; } List repasses = CriarRepasses(pagamento); repasses = await Servico.IncluirVendedores(repasses); if (!Servico.Sucesso) { Repasses = await VendedorServico.BuscaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); SelectedPagamento = null; Loading(isLoading: false); return null; } string tipodoc = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("NA PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("NO ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); repasses?.ForEach(delegate(VendedorParcela x) { string descricao = "VENDEDOR " + x.Vendedor.Nome + " ADICIONADO, " + tipodoc; RegistrarAcao(descricao, ((DomainBase)x).Id, (TipoTela)37, $"{GerarObs(SelectedDocumento)}{Environment.NewLine}VENDEDOR: {x.Vendedor.Nome}{Environment.NewLine}COMISSÃO TOTAL: {x.ValorTotal:C2}"); }); Repasses.AddRange(repasses); if (excluirCorretora) { await ExcluirVendedor(corretora, incluirCorretora: false); Documento selectedDocumento = SelectedDocumento; VendedorParcela? obj = ((IEnumerable)Repasses).FirstOrDefault((Func)((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id == 1)); selectedDocumento.VendedorPrincipal = ((obj != null) ? obj.Vendedor : null); } ToggleSnackBar("VENDEDOR ADICIONADO COM SUCESSO"); Repasses = await VendedorServico.BuscaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); SelectedPagamento = null; } CalculaComissao(SelectedDocumento, Parcelas); Loading(isLoading: false); return null; } public List> Validate(VendedorParcela pagamento) { List> list = new List>(); if (pagamento == null || SelectedDocumento == null) { list.Add(new KeyValuePair("pagamento|PAGAMENTO", "ERRO AO INSERIR VENDEDOR.")); return list; } if (pagamento.TipoVendedor == null || pagamento.Vendedor == null) { return list; } if (Repasses == null) { Repasses = new List(); } if (Repasses.Count > 0) { if (Repasses.All((VendedorParcela x) => x.Parcela == null)) { if (((DomainBase)SelectedDocumento).Id > 0) { ObservableCollection parcelas = Parcelas; if (parcelas != null && parcelas.Count > 0) { goto IL_00da; } } if (SelectedDocumento.Tipo == 1) { goto IL_00da; } } decimal value = Repasses.Where(delegate(VendedorParcela x) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Invalid comparison between Unknown and I4 if ((int)x.Parcela.SubTipo == 1) { decimal? porcentagemRepasse = x.PorcentagemRepasse; decimal num = 100; if (!((porcentagemRepasse.GetValueOrDefault() == num) & porcentagemRepasse.HasValue)) { return (int)pagamento.Repasse.Forma.GetValueOrDefault() == 1; } return false; } return false; }).Sum((VendedorParcela x) => x.ValorRepasse.GetValueOrDefault()) + pagamento.ValorRepasse.GetValueOrDefault(); decimal value2 = (SelectedDocumento.AdicionalComiss ? (SelectedDocumento.PremioLiquido + SelectedDocumento.PremioAdicional) : SelectedDocumento.PremioLiquido) * SelectedDocumento.Comissao * 0.01m; if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 15) && Math.Abs(value) > Math.Abs(value2) + Tolerancia) { list.Add(new KeyValuePair("ValorRepasse|VALOR DO REPASSE", "O TOTAL DE COMISSÃO PAGA NÃO PODE SER SUPERIOR A COMISSÃO PREVISTA PARA RECEBIMENTO.")); } if (Repasses.Where((VendedorParcela vendedorParcela) => vendedorParcela.Repasse != null && (int)vendedorParcela.Repasse.Tipo.GetValueOrDefault() != 3).Any((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id == ((DomainBase)pagamento.TipoVendedor).Id && !x.Vendedor.Corretora && (int)x.Parcela.SubTipo == 1)) { list.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", "JÁ EXISTE UM VENDEDOR DO TIPO " + pagamento.TipoVendedor.Descricao + " ADICIONADO AO DOCUMENTO.")); } if (Repasses.Any((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)pagamento.Vendedor).Id && (int)x.Parcela.SubTipo == 1)) { list.Add(new KeyValuePair("Nome|VENDEDOR", "VENDEDOR " + pagamento.Vendedor.Nome + " JÁ ADICIONADO AO DOCUMENTO.")); } } long id = ((DomainBase)pagamento.Vendedor).Id; Repasse repasse = pagamento.Repasse; if (id != ((repasse != null) ? new long?(((DomainBase)repasse.Vendedor).Id) : null)) { list.Add(new KeyValuePair("ValorRepasse|VALOR DO REPASSE", "PERCENTUAL DE REPASSE DEVE SER SELECIONADO")); } return list; IL_00da: list.Add(new KeyValuePair("|PARCELA", "PARCELA DEVE SER SELECIONADA PARA A INCLUSÃO DO VENDEDOR.")); return list; } public List> ValidateEspecial(VendedorParcela pagamento) { //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Invalid comparison between Unknown and I4 List> list = new List>(); if (SelectedParcela == null) { list.Add(new KeyValuePair("SelectedParcela|PARCELA", "PARCELA DEVE SER SELECIONADA PARA A INCLUSÃO DO VENDEDOR.")); return list; } if (Repasses == null) { Repasses = new List(); } decimal? num = Repasses.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)pagamento.Parcela).Id).Sum((VendedorParcela x) => x.ValorRepasse) + pagamento.ValorRepasse; decimal valor = SelectedParcela.Valor; decimal value = (SelectedParcela.DataRecebimento.HasValue ? SelectedParcela.ValorComDesconto : (valor * SelectedParcela.Comissao * 0.01m)); if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 15) && num.HasValue && Math.Abs(num.Value) > Math.Abs(value) + Tolerancia) { list.Add(new KeyValuePair("SelectedParcela|VALOR DO REPASSE", "O TOTAL DE COMISSÃO PAGA NÃO PODE SER SUPERIOR A COMISSÃO PREVISTA PARA RECEBIMENTO.")); } if (pagamento.Parcela == null) { if (Repasses.Any((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id == ((DomainBase)pagamento.TipoVendedor).Id && !x.Vendedor.Corretora)) { list.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", "JÁ EXISTE UM VENDEDOR DO TIPO " + pagamento.TipoVendedor.Descricao + " ADICIONADO AO DOCUMENTO.")); } if (Repasses.Any((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)pagamento.Vendedor).Id)) { list.Add(new KeyValuePair("Nome|VENDEDOR", "VENDEDOR " + pagamento.Vendedor.Nome + " JÁ ADICIONADO AO DOCUMENTO")); } return list; } if ((int)pagamento.Parcela.SubTipo == 1) { if (Repasses.Any(delegate(VendedorParcela x) { long id = ((DomainBase)x.TipoVendedor).Id; TipoVendedor tipoVendedor = pagamento.TipoVendedor; return id == ((tipoVendedor != null) ? new long?(((DomainBase)tipoVendedor).Id) : null) && !x.Vendedor.Corretora && ((DomainBase)x.Parcela).Id == ((DomainBase)pagamento.Parcela).Id; })) { list.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", "JÁ EXISTE UM VENDEDOR DO TIPO " + pagamento.TipoVendedor.Descricao + " ADICIONADO AO DOCUMENTO.")); } if (Repasses.Any((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)pagamento.Vendedor).Id && ((DomainBase)x.Parcela).Id == ((DomainBase)pagamento.Parcela).Id)) { list.Add(new KeyValuePair("Nome|VENDEDOR", "VENDEDOR " + pagamento.Vendedor.Nome + " JÁ ADICIONADO AO DOCUMENTO")); } return list; } if (Repasses.Any((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)pagamento.Parcela).Id && ((DomainBase)x.TipoVendedor).Id == ((DomainBase)pagamento.TipoVendedor).Id && !x.Vendedor.Corretora)) { list.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", "JÁ EXISTE UM VENDEDOR DO TIPO " + pagamento.TipoVendedor.Descricao + " ADICIONADO A PARCELA.")); } if (Repasses.Any((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)pagamento.Parcela).Id && ((DomainBase)x.Vendedor).Id == ((DomainBase)pagamento.Vendedor).Id)) { list.Add(new KeyValuePair("Nome|VENDEDOR", "VENDEDOR " + pagamento.Vendedor.Nome + " JÁ ADICIONADO A PARCELA")); } return list; } public List> HabilitarVendedor(int editarParcelaTipo = 0) { List> list = new List>(); if (editarParcelaTipo == 4) { if (SelectedParcela != null) { Parcela selectedParcela = SelectedParcela; list.AddRange((selectedParcela != null) ? selectedParcela.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 9), Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 11), EditandoParcela, Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 16)) : null); } } else { list.AddRange(SelectedDocumento.Validate(IsEndosso, Recursos.Configuracoes.Any((ConfiguracaoSistema c) => (int)c.Configuracao == 11))); } return list; } public async Task ExcluirVendedor(VendedorParcela pagamento, bool incluirCorretora = true) { if (IsEndosso && ((DomainBase)SelectedDocumento).Id == 0L) { RemoverVendedor(((DomainBase)pagamento.Vendedor).Id); ToggleSnackBar("VENDEDOR EXCLUÍDO COM SUCESSO"); return; } if (!AllowEditApolice && !IsFatura && (int)SelectedParcela.SubTipo == 1) { await ShowMessage("O VENDEDOR " + pagamento.Vendedor.Nome.ToUpper() + " NÃO PODE SER EXCLUÍDO." + Environment.NewLine + "JÁ EXISTEM RECEBIMENTOS OU PAGAMENTOS DE COMISSÃO PARA ESSE DOCUMENTO."); return; } if (((DomainBase)SelectedDocumento).Id > 0 && (IsFatura || (int)SelectedParcela.SubTipo != 1) && ((((DomainBase)SelectedParcela).Id > 0 && SelectedParcela.DataRecebimento.HasValue) || Repasses.Any((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id && x.DataPagamento.HasValue))) { await ShowMessage("O VENDEDOR " + pagamento.Vendedor.Nome.ToUpper() + " NÃO PODE SER EXCLUÍDO." + Environment.NewLine + "JÁ EXISTEM RECEBIMENTOS OU PAGAMENTOS DE COMISSÃO PARA ESSA FATURA."); return; } if (((DomainBase)SelectedDocumento).Id == 0L) { RemoverVendedor(((DomainBase)pagamento.Vendedor).Id); ToggleSnackBar("VENDEDOR EXCLUÍDO COM SUCESSO"); return; } List source = (((int)SelectedParcela.SubTipo == 1 && !IsFatura) ? Repasses.Where((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)pagamento.Vendedor).Id && x.Parcela.NumeroParcela != 999).ToList() : Repasses.Where((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == ((DomainBase)pagamento.Vendedor).Id && ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id).ToList()); List vendedores = source.Distinct().ToList(); if (!(await Servico.ExcluirPagamento(vendedores))) { await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); return; } if (((DomainBase)SelectedParcela).Id > 0) { string tipodoc = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("NA PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("NO ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); vendedores.ForEach(delegate(VendedorParcela x) { string descricao = "VENDEDOR " + x.Vendedor.Nome + " EXCLUÍDO, " + tipodoc; RegistrarAcao(descricao, ((DomainBase)x).Id, (TipoTela)37, $"{GerarObs(SelectedDocumento)}{Environment.NewLine}VENDEDOR: {x.Vendedor.Nome}{Environment.NewLine}COMISSÃO TOTAL: {x.ValorTotal:C2}"); }); } RemoverVendedor(((DomainBase)pagamento.Vendedor).Id); bool flag = ((IsFatura || (int)SelectedParcela.SubTipo != 1) ? Repasses.Any((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id && ((DomainBase)x.TipoVendedor).Id == 1) : Repasses.Any((VendedorParcela x) => (int)x.Parcela.SubTipo == 1 && ((DomainBase)x.TipoVendedor).Id == 1 && !x.CoCorretagem)); if (((DomainBase)pagamento.TipoVendedor).Id == 1 && incluirCorretora && !flag) { VendedorParcela val = await IncluirPropriaCorretora(); if (val != null) { Repasses.Add(val); Documento selectedDocumento = SelectedDocumento; VendedorParcela? obj = ((IEnumerable)Repasses).FirstOrDefault((Func)((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id == 1)); selectedDocumento.VendedorPrincipal = ((obj != null) ? obj.Vendedor : null); } } if (Repasses != null) { Pagamentos = new ObservableCollection(Repasses.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id).ToList()); } ToggleSnackBar("VENDEDOR EXCLUÍDO COM SUCESSO"); CalculaComissao(SelectedDocumento, Parcelas); } private void RemoverVendedor(long id) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Invalid comparison between Unknown and I4 //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Invalid comparison between Unknown and I4 ((((DomainBase)SelectedDocumento).Id == 0L || ((int)SelectedParcela.SubTipo == 1 && !IsFatura)) ? Repasses.Where((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == id).ToList() : Repasses.Where((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == id && ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id).ToList()).ForEach(delegate(VendedorParcela x) { Repasses.Remove(x); }); ((((DomainBase)SelectedDocumento).Id == 0L || ((int)SelectedParcela.SubTipo == 1 && !IsFatura)) ? Pagamentos.Where((VendedorParcela x) => ((DomainBase)x.Vendedor).Id == id).ToList() : Pagamentos.Where(delegate(VendedorParcela x) { if (((DomainBase)x.Vendedor).Id == id) { Parcela parcela = x.Parcela; return ((parcela != null) ? ((DomainBase)parcela).Id : 0) == ((DomainBase)SelectedParcela).Id; } return false; }).ToList()).ForEach(delegate(VendedorParcela x) { Pagamentos.Remove(x); }); } private async Task IncluirPropriaCorretora() { if (Parcelas.Count == 0) { return null; } VendedorParcela val = PropriaCorretora(); Parcela val3 = (val.Parcela = (Parcela)(((int)SelectedParcela.SubTipo == 1 && !IsFatura) ? ((object)((IEnumerable)Parcelas).FirstOrDefault((Func)((Parcela x) => x.NumeroParcela == 1))) : ((object)SelectedParcela))); val.Documento = SelectedDocumento; if (val3 != null && ((DomainBase)val3).Id == 0L) { return val; } return await Servico.IncluirVendedor(val); } public async Task CancelarAlteracao() { Acesso = (AcessoApolice)0; if (CancelDocumento != null && ((DomainBase)CancelDocumento).Id != 0L) { await SelecionaDocumento(CancelDocumento); } else { SelectedDocumento = null; } Anotacoes = string.Empty; base.EnableFields = false; Gestor.Application.Actions.Actions.EnableMainMenu?.Invoke(obj: true); Gestor.Application.Actions.Actions.EnableMenu?.Invoke(obj: true); Gestor.Application.Actions.Actions.EnablePesquisarClientes?.Invoke(obj: true); } public async Task AlterarVencimento() { if (SelectedParcela == null) { return; } Loading(isLoading: true); bool flag = (int)SelectedParcela.SubTipo == 1 && !IsFatura && (decimal)SelectedParcela.NumeroParcela < SelectedDocumento.NumeroParcelas; if (flag) { flag = await ShowMessage("DESEJA ALTERAR O VENCIMENTO PARA AS PRÓXIMAS PARCELAS?", "SIM", "NÃO"); } bool alterarDemais = flag; if ((int)SelectedParcela.SubTipo == 1 && !IsFatura) { DateTime vencimento = SelectedParcela.Vencimento; decimal valor = SelectedDocumento.PremioTotal - Parcelas.Where((Parcela x) => (int)x.SubTipo == 1 && ((DomainBase)x).Id != ((DomainBase)SelectedParcela).Id).Sum((Parcela x) => x.Valor); decimal num = SelectedDocumento.PremioTotal - Parcelas.Where((Parcela x) => (int)x.SubTipo == 1 && ((DomainBase)x).Id < ((DomainBase)SelectedParcela).Id).Sum((Parcela x) => x.Valor); num -= SelectedParcela.Valor; decimal num2 = SelectedDocumento.NumeroParcelas - (decimal)SelectedParcela.NumeroParcela; if (num2 == 0m) { num2 = 1m; } decimal valorDemais = ((num2 > 0m) ? (num / num2) : 0m); if (valorDemais == 0m) { SelectedParcela.Valor = valor; } List parcelas = new List { SelectedParcela }; decimal num3 = Math.Abs(valorDemais); decimal? tolerancia = SelectedDocumento.Controle.Seguradora.Tolerancia; if (((num3 > tolerancia.GetValueOrDefault()) & tolerancia.HasValue) && !Parcelas.Any((Parcela x) => (int)x.SubTipo == 1 && x.NumeroParcela > SelectedParcela.NumeroParcela)) { SelectedParcela.Valor = valor; } Parcelas.Where((Parcela x) => (int)x.SubTipo == 1 && x.NumeroParcela != SelectedParcela.NumeroParcela).ToList().ForEach(delegate(Parcela x) { if (x.NumeroParcela > SelectedParcela.NumeroParcela) { if (alterarDemais) { vencimento = vencimento.AddMonths(1); if (SelectedDocumento.Vigencia2.HasValue) { DateTime value = vencimento; DateTime? vigencia = SelectedDocumento.Vigencia2; if (!(value < vigencia) && !Recursos.Configuracoes.Any((ConfiguracaoSistema c) => (int)c.Configuracao == 11)) { goto IL_00d0; } } x.Vencimento = vencimento; } goto IL_00d0; } goto IL_012b; IL_012b: parcelas.Add(x); return; IL_00d0: x.Valor = ((valorDemais > 0m) ? valorDemais : x.Valor); x.Comissao = ((x.Comissao == 0m) ? SelectedDocumento.Comissao : x.Comissao); goto IL_012b; }); Repasses?.ForEach(delegate(VendedorParcela x) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Invalid comparison between Unknown and I4 if (!x.CoCorretagem && x.Repasse != null && x.Parcela != null && (((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id || alterarDemais) && !x.DataPagamento.HasValue) { Parcela val = ((IEnumerable)parcelas).FirstOrDefault((Func)((Parcela y) => ((DomainBase)y).Id == ((DomainBase)x.Parcela).Id)); x.Parcela = ((val != null) ? val : x.Parcela); if ((int)x.Repasse.Base.GetValueOrDefault() == 3 && val != null) { x.DataPrePagamento = ((x.Parcela.Vencimento == DateTime.MinValue) ? SelectedDocumento.Vigencia1 : x.Parcela.Vencimento); } } }); foreach (Parcela x2 in parcelas) { if (x2.NumeroParcela >= SelectedParcela.NumeroParcela) { x2.Documento = SelectedDocumento; if (((DomainBase)x2).Id != ((DomainBase)SelectedParcela).Id) { x2.Valor = valorDemais; } } List auxRepasse = Repasses?.Where((VendedorParcela y) => ((DomainBase)y.Parcela).Id == ((DomainBase)x2).Id).ToList(); ObservableCollection source = await ParcelaServico.BuscarParcelasAsync(((DomainBase)SelectedDocumento).Id); if (auxRepasse == null && auxRepasse.Count <= 0) { await ParcelaServico.Save(x2, source.ToList()); } else { await ParcelaServico.Save(x2, source.ToList(), auxRepasse); } string text = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("PROPOSTA " + SelectedDocumento.Proposta) : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("APÓLICE " + SelectedDocumento.Apolice) : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("PROPOSTA DE ENDOSSO " + SelectedDocumento.PropostaEndosso) : ("ENDOSSO " + SelectedDocumento.Endosso)))); string descricao = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? $"PARCELA {x2.NumeroParcela} ALTERADA, {text}" : ("FATURA " + x2.Fatura + " ALTERADA, " + text)); RegistrarAcao(descricao, ((DomainBase)x2).Id, (TipoTela)5, GerarObs(SelectedDocumento)); if (!ParcelaServico.Sucesso && x2.NumeroParcela >= SelectedParcela.NumeroParcela) { await CarregarParcelas(SelectedDocumento); Loading(isLoading: false); return; } } } else { SelectedParcela.Documento = SelectedDocumento; Repasses?.ForEach(delegate(VendedorParcela x) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Invalid comparison between Unknown and I4 //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected I4, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Invalid comparison between Unknown and I4 //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Invalid comparison between Unknown and I4 //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Invalid comparison between Unknown and I4 if (!x.CoCorretagem && x.Repasse != null && x.Parcela != null && ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id && !x.DataPagamento.HasValue) { if ((int)x.Repasse.Forma.GetValueOrDefault() == 1) { x.DataPrePagamento = SelectedParcela.DataRecebimento; } BaseRepasse? @base = x.Repasse.Base; if (@base.HasValue) { BaseRepasse valueOrDefault = @base.GetValueOrDefault(); switch (valueOrDefault - 1) { case 2: x.DataPrePagamento = ((x.Parcela.Vencimento == DateTime.MinValue) ? SelectedDocumento.Vigencia1 : x.Parcela.Vencimento); break; case 0: x.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? SelectedParcela.VigenciaIncial : new DateTime?(SelectedDocumento.Vigencia1)); break; case 1: x.DataPrePagamento = x.Parcela.DataCriacao; break; case 3: x.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? x.Parcela.Emissao : SelectedDocumento.Emissao); break; case 4: x.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? x.Parcela.Emissao : SelectedDocumento.Remessa); break; } } } }); ObservableCollection source2 = await ParcelaServico.BuscarParcelasAsync(((DomainBase)SelectedDocumento).Id); SelectedParcela = await ParcelaServico.Save(SelectedParcela, source2.ToList(), Repasses?.Where((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id).ToList()); if (!ParcelaServico.Sucesso) { await CarregarParcelas(SelectedDocumento); Loading(isLoading: false); return; } } ToggleSnackBar("PARCELAS ALTERADAS COM SUCESSO"); await CarregarParcelas(SelectedDocumento); Loading(isLoading: false); } public async Task AdicionarParcelaEspecial() { if (SelectedParcela == null || CriandoParcelaEspecial) { return; } CriandoParcelaEspecial = true; if (SelectedPagamento == null || SelectedPagamento.Vendedor.Corretora) { SelectedPagamento = PropriaCorretora(); } else { List> list = await AdicionarVendedorParcelaEspecial(); if (list.Count > 0) { _criandoParcelaEspecial = false; await ShowMessage(list, " PROCESSO INTERROMPIDO, PARCELA/FATURA SEM VENDENDEDOR", "OK"); return; } } SelectedParcela.Documento = SelectedDocumento; DateTime vencimento = SelectedParcela.Vencimento; DateTime? recebimento = SelectedParcela.DataRecebimento; DateTime? credito = SelectedParcela.DataCredito; DateTime? controle = SelectedParcela.DataControle; int numeroParcela = SelectedParcela.NumeroParcela; DateTime? vigencia1 = SelectedParcela.VigenciaIncial; DateTime? vigencia2 = SelectedParcela.VigenciaFinal; DateTime? emissao = SelectedParcela.Emissao; long result; long fatura = (long.TryParse(string.IsNullOrWhiteSpace(ValidationHelper.OnlyNumber(SelectedParcela.Fatura)) ? "1" : ValidationHelper.OnlyNumber(SelectedParcela.Fatura), out result) ? result : 1); if (QuantidadeFaturas == 0 || !IsFatura) { QuantidadeFaturas = 1; } if (QuantidadeFaturas > 12) { CriandoParcelaEspecial = false; await ShowMessage("NÃO É POSSIVEL REPLICAR MAIS QUE 12 VEZES A MESMA FATURA. PROCESSO CANCELADO"); return; } for (int i = 0; i < QuantidadeFaturas; i++) { SelectedParcela.Vencimento = vencimento.AddMonths(i); SelectedParcela.VigenciaIncial = vigencia1?.AddMonths(i); SelectedParcela.VigenciaFinal = vigencia2?.AddMonths(i); SelectedParcela.Emissao = emissao?.AddMonths(i); SelectedParcela.DataRecebimento = recebimento?.AddMonths(i); SelectedParcela.DataCredito = credito?.AddMonths(i); SelectedParcela.DataControle = controle?.AddMonths(i); SelectedParcela.NumeroParcela = numeroParcela + i; if (i > 0) { fatura++; SelectedParcela.Fatura = $"{fatura}"; SelectedParcela.DataQuitacao = null; } Repasses?.ForEach(delegate(VendedorParcela x) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Invalid comparison between Unknown and I4 //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected I4, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Invalid comparison between Unknown and I4 //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Invalid comparison between Unknown and I4 //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Invalid comparison between Unknown and I4 if (x.Repasse != null) { if ((int)x.Repasse.Forma.GetValueOrDefault() == 1) { x.DataPrePagamento = SelectedParcela.DataRecebimento; } x.Parcela = SelectedParcela; BaseRepasse? @base = x.Repasse.Base; if (@base.HasValue) { BaseRepasse valueOrDefault = @base.GetValueOrDefault(); switch (valueOrDefault - 1) { case 2: x.DataPrePagamento = ((x.Parcela.Vencimento == DateTime.MinValue) ? SelectedDocumento.Vigencia1 : x.Parcela.Vencimento); break; case 0: x.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? x.Parcela.VigenciaIncial : new DateTime?(SelectedDocumento.Vigencia1)); break; case 1: x.DataPrePagamento = x.Parcela.DataCriacao; break; case 3: x.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? x.Parcela.Emissao : SelectedDocumento.Emissao); break; case 4: x.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? x.Parcela.Emissao : SelectedDocumento.Remessa); break; } } } }); if (Repasses == null) { Repasses = new List { PropriaCorretora() }; } if (Repasses.All((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id != 1)) { Repasses.Add(PropriaCorretora()); } Parcela selectedParcela = await ParcelaServico.Save(SelectedParcela, Parcelas.ToList(), Repasses); if (i == QuantidadeFaturas - 1) { SelectedParcela = selectedParcela; } } QuantidadeFaturas = 0; string text = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("NA PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("NO ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); string descricao = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? ("PARCELA ESPECIAL ADICIONADA, " + text) : ("FATURA " + SelectedParcela.Fatura + " ADICIONADA, " + text)); RegistrarAcao(descricao, ((DomainBase)SelectedParcela).Id, (TipoTela)5, GerarObs(SelectedDocumento)); if (ParcelaServico.Sucesso) { ToggleSnackBar(((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? "PARCELA ESPECIAL ADICIONADA COM SUCESSO" : "FATURA ADICIONADA COM SUCESSO"); } await CarregarParcelas(SelectedDocumento); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); CalculaComissao(SelectedDocumento, Parcelas); BaixarParcelas = false; CriandoParcelaEspecial = false; } public void EditarParcelaEspecial() { AllowEditVendedor = true; } public async Task>> AdicionarVendedorParcelaEspecial() { List> list = new List>(); if (SelectedPagamento == null) { list.Add(new KeyValuePair("SelectedPagamento|PAGAMENTO", "ERRO AO INCLUIR VENDEDOR.")); return list; } if (SelectedPagamento.Repasse == null) { list.Add(new KeyValuePair("Repasse|REPASSE", "ERRO AO INCLUIR VENDEDOR.")); return list; } SelectedPagamento.Parcela = SelectedParcela; if ((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2 && (int)SelectedPagamento.Repasse.Forma.GetValueOrDefault() == 3) { ShowMessage("NÃO É POSSÍVEL ADICIONAR UM VENDEDOR COM A FORMA DE PAGAMENTO À PRAZO EM DOCUMENTOS DO TIPO FATURA"); return null; } Repasse repasse = SelectedPagamento.Repasse; List vinculo = ((repasse == null) ? null : repasse.Vinculo?.Where((VinculoRepasse x) => ((DomainBase)x.TipoVendedor).Id == ((DomainBase)SelectedPagamento.TipoVendedor).Id).ToList()); List pagamentos = new List { SelectedPagamento }; bool renovacao = (SelectedDocumento.NegocioCorretora.HasValue ? ((int)SelectedDocumento.NegocioCorretora.GetValueOrDefault() == 1) : ((int)SelectedDocumento.Situacao == 2 && SelectedDocumento.Negocio.HasValue && (int)SelectedDocumento.Negocio.GetValueOrDefault() == 1)); bool flag = vinculo != null && vinculo.Count > 0; if (flag) { flag = await ShowMessage("DESEJA ADICIONAR OS REPASSES VINCULADOS?", "SIM", "NÃO"); } if (flag) { foreach (VinculoRepasse item2 in vinculo) { decimal value = Funcoes.CalculaRepasse(item2.RepasseVinculo, SelectedPagamento.Parcela, SelectedPagamento.Parcela == null || (int)SelectedPagamento.Parcela.SubTipo == 1); VendedorParcela item = new VendedorParcela { TipoVendedor = item2.TipoVendedorVinculo, Vendedor = item2.RepasseVinculo.Vendedor, Repasse = item2.RepasseVinculo, Documento = SelectedPagamento.Documento, Parcela = SelectedPagamento.Parcela, PorcentagemRepasse = (renovacao ? item2.RepasseVinculo.ValorRenovacao : item2.RepasseVinculo.ValorNovo), ValorRepasse = value, ValorTotal = value }; pagamentos.Add(item); } } foreach (VendedorParcela item3 in pagamentos) { VendedorParcela val = item3; list = val.Validate(); list.AddRange(ValidateEspecial(val)); if (list.Count > 0) { if (SelectedPagamento == null) { SelectedPagamento = val; } return list; } if (val.Repasse != null) { switch (val.Repasse.Base) { case 2L: val.DataPrePagamento = ((val.Parcela.Vencimento == DateTime.MinValue) ? SelectedDocumento.Vigencia1 : val.Parcela.Vencimento); break; case 0L: val.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? val.Parcela.VigenciaIncial : new DateTime?(SelectedDocumento.Vigencia1)); break; case 1L: val.DataPrePagamento = val.Parcela.DataCriacao; break; case 3L: val.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? val.Parcela.Emissao : SelectedDocumento.Emissao); break; case 4L: val.DataPrePagamento = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? val.Parcela.Emissao : SelectedDocumento.Remessa); break; } } if (Pagamentos == null) { Pagamentos = new ObservableCollection(); } VendedorParcela corretora = ((IEnumerable)Repasses).FirstOrDefault((Func)((VendedorParcela x) => ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id && ((DomainBase)x.TipoVendedor).Id == 1 && x.Vendedor.Corretora)); bool excluirCorretora = ((DomainBase)val.TipoVendedor).Id == 1 && corretora != null; if (((DomainBase)SelectedParcela).Id == 0L) { Repasses.Add(val); Pagamentos.Add(val); SelectedPagamento = null; if ((IsFatura || (int)SelectedParcela.SubTipo != 1) && excluirCorretora) { await ExcluirVendedor(corretora, incluirCorretora: false); } continue; } if ((int)val.Repasse.Forma.GetValueOrDefault() == 1) { val.DataPrePagamento = SelectedParcela.DataRecebimento; } List repasses = new List { val }; repasses = await Servico.IncluirVendedores(repasses); string tipodoc = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("NA PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("NO ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); repasses?.ForEach(delegate(VendedorParcela x) { string descricao = "VENDEDOR " + x.Vendedor.Nome + " ADICIONADO A PARCELA ESPECIAL, " + tipodoc; RegistrarAcao(descricao, ((DomainBase)x).Id, (TipoTela)37, $"{GerarObs(SelectedDocumento)}{Environment.NewLine}VENDEDOR: {x.Vendedor.Nome}{Environment.NewLine}COMISSÃO TOTAL: {x.ValorTotal:C2}"); }); Repasses.AddRange(repasses); if (excluirCorretora) { await ExcluirVendedor(corretora, incluirCorretora: false); } Repasses = await VendedorServico.BuscaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); SelectedPagamento = null; } ToggleSnackBar("VENDEDOR ADICIONADO COM SUCESSO"); return null; } internal async Task BaixarComissao() { if (SelectedParcela == null) { return; } Loading(isLoading: true); int num; if (IsFatura) { Parcela? obj = ((IEnumerable)Parcelas.OrderBy((Parcela x) => x.NumeroParcela)).LastOrDefault((Func)((Parcela x) => (int)x.SubTipo == 1)); num = ((((obj != null) ? new long?(((DomainBase)obj).Id) : null) == ((DomainBase)SelectedParcela).Id) ? 1 : 0); } else { num = 0; } bool ultimafatura = (byte)num != 0; SelectedParcela.Documento = SelectedDocumento; Parcela selectedParcela = SelectedParcela; List parcelas = Parcelas.ToList(); List repasses = Repasses; Documento selectedDocumento = SelectedDocumento; decimal? obj2; if (selectedDocumento == null) { obj2 = null; } else { Controle controle = selectedDocumento.Controle; if (controle == null) { obj2 = null; } else { Seguradora seguradora = controle.Seguradora; obj2 = ((seguradora != null) ? seguradora.Tolerancia : null); } } SelectedParcela = await Funcoes.BaixarComissao(selectedParcela, parcelas, repasses, obj2 ?? Tolerancia); Documento selectedDocumento2 = SelectedDocumento; string text; if (selectedDocumento2 == null || selectedDocumento2.Tipo != 0 || !string.IsNullOrEmpty(SelectedDocumento.Apolice)) { Documento selectedDocumento3 = SelectedDocumento; if (selectedDocumento3 == null || selectedDocumento3.Tipo != 0 || string.IsNullOrEmpty(SelectedDocumento.Apolice)) { Documento selectedDocumento4 = SelectedDocumento; if (!string.IsNullOrEmpty((selectedDocumento4 != null) ? selectedDocumento4.Endosso : null)) { text = "ENDOSSO " + SelectedDocumento.Endosso; } else { Documento selectedDocumento5 = SelectedDocumento; text = "PROPOSTA DE ENDOSSO " + ((selectedDocumento5 != null) ? selectedDocumento5.PropostaEndosso : null); } } else { text = "APÓLICE " + SelectedDocumento.Apolice; } } else { text = "PROPOSTA " + SelectedDocumento.Proposta; } string text2 = text; Documento selectedDocumento6 = SelectedDocumento; string descricao = ((selectedDocumento6 != null && (int)selectedDocumento6.TipoRecebimento.GetValueOrDefault() == 1) ? $"PARCELA {SelectedParcela.NumeroParcela} BAIXADA, {text2}" : ("FATURA " + SelectedParcela.Fatura + " BAIXADA, " + text2)); RegistrarAcao(descricao, ((DomainBase)SelectedParcela).Id, (TipoTela)5, GerarObs(SelectedDocumento)); if (SelectedDocumento != null) { await CarregarParcelas(SelectedDocumento); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); CalculaComissao(SelectedDocumento, Parcelas); } await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); BaixarParcelas = false; AllowEditApolice = Parcelas.Where((Parcela x) => (int)x.SubTipo == 1).All((Parcela x) => !x.DataRecebimento.HasValue) && Repasses.Where((VendedorParcela x) => (int)x.Parcela.SubTipo == 1).All((VendedorParcela x) => !x.DataPagamento.HasValue); Loading(isLoading: false); bool flag = ultimafatura; if (flag) { flag = await ShowMessage("DESEJA INCLUIR A PRÓXIMA FATURA?", "SIM", "NÃO"); } if (flag) { UltimaFatura = true; } ToggleSnackBar("PARCELA BAIXADA COM SUCESSO"); } internal async Task ExcluirBaixa() { if (SelectedParcela != null && await ShowMessage("DESEJA REALMENTE EXCLUIR A BAIXA DA PARCELA SELECIONADA?" + Environment.NewLine + "ESSE PROCEDIMENTO É IRREVERSÍVEL.", "SIM", "NÃO")) { Loading(isLoading: true); SelectedParcela.Documento = SelectedDocumento; SelectedParcela = await Funcoes.ExcluirBaixa(SelectedParcela, Repasses, Parcelas.ToList()); string text = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("PROPOSTA " + SelectedDocumento.Proposta) : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("APÓLICE " + SelectedDocumento.Apolice) : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("PROPOSTA DE ENDOSSO " + SelectedDocumento.PropostaEndosso) : ("ENDOSSO " + SelectedDocumento.Endosso)))); string descricao = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? $"BAIXA DA PARCELA {SelectedParcela.NumeroParcela} EXCLUÍDA, {text}" : ("BAIXA DA FATURA " + SelectedParcela.Fatura + " EXCLUÍDA, " + text)); RegistrarAcao(descricao, ((DomainBase)SelectedParcela).Id, (TipoTela)5, GerarObs(SelectedDocumento)); await CarregarParcelas(SelectedDocumento); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); CalculaComissao(SelectedDocumento, Parcelas); await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); BaixarParcelas = false; AllowEditApolice = Parcelas.Where((Parcela x) => (int)x.SubTipo == 1).All((Parcela x) => !x.DataRecebimento.HasValue) && Repasses.Where((VendedorParcela x) => (int)x.Parcela.SubTipo == 1).All((VendedorParcela x) => !x.DataPagamento.HasValue); Loading(isLoading: false); ToggleSnackBar("BAIXA EXCLUÍDA COM SUCESSO"); } } public async Task ExcluirParcela() { if (SelectedParcela == null || ((int)SelectedParcela.SubTipo == 1 && (int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1)) { return; } if ((int)SelectedParcela.SubTipo == 1) { Parcela val = Parcelas.OrderBy((Parcela x) => x.NumeroParcela).Last((Parcela x) => (int)x.SubTipo == 1); if (((DomainBase)SelectedParcela).Id != ((DomainBase)val).Id) { await ShowMessage("A FATURA NÃO PODE SER EXCLUÍDA POIS HÁ FATURAS CADASTRADAS ACIMA DA SELECIONADA."); return; } } if (await ShowMessage("DESEJA REALMENTE EXCLUIR A PARCELA SELECIONADA?" + Environment.NewLine + "ESSE PROCEDIMENTO É IRREVERSÍVEL.", "SIM", "NÃO")) { Loading(isLoading: true); if (await ParcelaServico.Delete(SelectedParcela, Parcelas.ToList())) { ToggleSnackBar(((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? "PARCELA EXCLUÍDA COM SUCESSO" : "FATURA EXCLUÍDA COM SUCESSO"); string text = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("PROPOSTA " + SelectedDocumento.Proposta) : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("APÓLICE " + SelectedDocumento.Apolice) : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("PROPOSTA DE ENDOSSO " + SelectedDocumento.PropostaEndosso) : ("ENDOSSO " + SelectedDocumento.Endosso)))); string descricao = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1) ? $"PARCELA {SelectedParcela.NumeroParcela} EXCLUÍDA, {text}" : ("FATURA " + SelectedParcela.Fatura + " EXCLUÍDA, " + text)); RegistrarAcao(descricao, ((DomainBase)SelectedParcela).Id, (TipoTela)5, GerarObs(SelectedDocumento)); } await CarregarParcelas(SelectedDocumento); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(Parcelas.FirstOrDefault()); BaixarParcelas = false; if (Parcelas == null || Parcelas.Count == 0) { VisibilityExcluirParcela = (Visibility)2; VisibilityReplicarFatura = (Visibility)2; BaixarParcelaVisibility = (Visibility)2; } Loading(isLoading: false); AllowEditVendedor = Parcelas.Any(); } } public async Task ExcluirApolice() { if (SelectedDocumento == null) { return; } if (!AllowEditApolice || Parcelas.Any((Parcela x) => x.DataRecebimento.HasValue) || Repasses.Any((VendedorParcela x) => x.DataPagamento.HasValue)) { await ShowMessage("DOCUMENTO NÃO PODE SER EXCLUÍDO POIS POSSUI BAIXAS DE COMISSÃO OU PAGAMENTO DE VENDEDORES."); return; } if (SelectedDocumento.Tipo > 0 && SelectedDocumento.Sinistro) { await ShowMessage("DOCUMENTO NÃO PODE SER EXCLUÍDO POIS POSSUI SINISTROS PARA UM OU MAIS DE SEUS ITENS."); return; } Documento documentoSelecionado = SelectedDocumento; string documento = ((documentoSelecionado.Tipo == 0 && string.IsNullOrEmpty(documentoSelecionado.Apolice)) ? "A PROPOSTA SELECIONADA" : ((documentoSelecionado.Tipo == 0 && !string.IsNullOrEmpty(documentoSelecionado.Apolice)) ? "A APÓLICE SELECIONADA" : "O ENDOSSO SELECIONADO")); int ordem = SelectedDocumento.Ordem; Documento? obj = ((IEnumerable)SelectedDocumento.Controle.Documentos.OrderByDescending((Documento x) => x.Ordem)).FirstOrDefault((Func)((Documento x) => (!x.Excluido && (int)x.Situacao != 7) || ((DomainBase)x).Id == ((DomainBase)SelectedDocumento).Id)); if (ordem != ((obj != null) ? obj.Ordem : SelectedDocumento.Ordem)) { await ShowMessage(documento + " NÃO PODE SER EXCLUÍDO(A) POIS POSSUEM DOCUMENTOS ATIVOS ACIMA."); } else { if (!(await ShowMessage("DESEJA REALMENTE EXCLUIR " + documento + "?" + Environment.NewLine + "ESSE PROCEDIMENTO É IRREVERSÍVEL.", "SIM", "NÃO"))) { return; } bool flag = documentoSelecionado.TipoEndosso.HasValue; if (flag) { flag = await ShowMessage("DESEJA DESFAZER AS ALTERAÇOES NOS ITENS VINCULADOS A ESSE ENDOSSO ?", "SIM", "NÃO"); } if (flag) { Documento? obj2 = ((IEnumerable)SelectedDocumento.Controle.Documentos.OrderByDescending((Documento x) => x.Ordem)).FirstOrDefault((Func)((Documento x) => !x.Excluido && (int)x.Situacao != 7 && x.Ordem > SelectedDocumento.Ordem)); if (((obj2 != null) ? new int?(obj2.Ordem) : null) > SelectedDocumento.Ordem) { await ShowMessage("NÃO É POSSIVEL DESFAZER AS ALTERAÇÕES, POIS " + documento + " POSSUE ENDOSSOS ATIVOS ACIMA."); return; } await DesfazerAlteracoes(); } string descricao = ((documentoSelecionado.Tipo == 0 && string.IsNullOrEmpty(documentoSelecionado.Apolice)) ? ("EXCLUIU PROPOSTA " + documentoSelecionado.Proposta) : ((documentoSelecionado.Tipo == 0 && !string.IsNullOrEmpty(documentoSelecionado.Apolice)) ? ("EXCLUIU APÓLICE " + documentoSelecionado.Apolice) : (string.IsNullOrEmpty(documentoSelecionado.Endosso) ? ("EXCLUIU PROPOSTA DE ENDOSSO " + documentoSelecionado.PropostaEndosso) : ("EXCLUIU ENDOSSO " + documentoSelecionado.Endosso)))); RegistrarAcao(descricao, ((DomainBase)SelectedDocumento).Id, (TipoTela)2, GerarObs(documentoSelecionado)); Loading(isLoading: true); string label = ((documentoSelecionado.Tipo == 0 && string.IsNullOrEmpty(documentoSelecionado.Apolice)) ? "PROPOSTA EXCLUÍDA" : ((documentoSelecionado.Tipo == 0 && !string.IsNullOrEmpty(documentoSelecionado.Apolice)) ? "APÓLICE EXCLUÍDA" : "ENDOSSO EXCLUÍDO")); documentoSelecionado.Excluido = true; Servico.Sucesso = true; await Servico.ExcluirCritica(((DomainBase)documentoSelecionado).Id); if (!Servico.Sucesso) { Loading(isLoading: false); return; } TarefaServico tarefaServico = TarefaServico; tarefaServico.Sucesso = await TarefaServico.ExcluirTarefasDocumento(((DomainBase)documentoSelecionado).Id); if (!TarefaServico.Sucesso) { Loading(isLoading: false); return; } Servico.Sucesso = true; if (documentoSelecionado.TipoEndosso.HasValue && (int)documentoSelecionado.TipoEndosso.GetValueOrDefault() == 2) { Documento apolice = ((IEnumerable)CancelDocumento.Controle.Documentos).FirstOrDefault((Func)((Documento x) => x.Tipo == 0 && !x.Excluido)); List endossos = CancelDocumento.Controle.Documentos.Where((Documento x) => x.Tipo == 1 && !x.Excluido).ToList(); if (apolice != null) { apolice.Situacao = (TipoSeguro)((apolice.SituacaoAnterior.HasValue && (int)apolice.SituacaoAnterior.GetValueOrDefault() != 3) ? ((int)apolice.SituacaoAnterior.Value) : (((int)apolice.NegocioCorretora.GetValueOrDefault() != 1) ? 1 : 2)); await Servico.Save(apolice, updateParcelas: false, criarParcelas: false); foreach (Documento item in endossos) { item.Situacao = apolice.Situacao; await Servico.Save(item, updateParcelas: false, criarParcelas: false); } } } await Servico.Excluir(documentoSelecionado); if (!Servico.Sucesso) { Loading(isLoading: false); return; } if (documentoSelecionado.Tipo > 0) { await Funcoes.OrganizarDocumentos(((DomainBase)documentoSelecionado.Controle).Id); await Funcoes.InativarItens(((DomainBase)documentoSelecionado).Id, ((DomainBase)documentoSelecionado.Controle.Ramo).Id); } if (Invoke) { ConsultaViewModel.DocumentoSelecionado = null; Gestor.Application.Actions.Actions.RecarregarDocumentos?.Invoke(null); } Loading(isLoading: false); ToggleSnackBar(label + " COM SUCESSO"); if (Invoke) { Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)21, ""); } } } private async Task DesfazerAlteracoes() { ObservableCollection itensApoMae = await new ItemServico().BuscarItems(((DomainBase)((IEnumerable)SelectedDocumento.Controle.Documentos).FirstOrDefault((Func)((Documento x) => !x.Excluido && (int)x.Situacao != 7 && x.Ordem == 0))).Id, (StatusItem)2); ObservableCollection itensDocumento = await new ItemServico().BuscarItems(((DomainBase)SelectedDocumento).Id, (StatusItem)2); List list = itensApoMae.Where((Item x) => x.IdDocumentoCancelado == ((DomainBase)SelectedDocumento).Id).ToList(); list.AddRange(itensApoMae.Where(delegate(Item x) { if (x.Substituido.HasValue) { long? substituido = x.Substituido; Item? obj = ((IEnumerable)itensDocumento).FirstOrDefault((Func)((Item d) => ((DomainBase)d).Id == x.Substituido)); return substituido == ((obj != null) ? new long?(((DomainBase)obj).Id) : null); } return false; })?.ToList()); if (list.Count == 0) { list = itensApoMae.Where((Item x) => x.Status != null && !ValidationHelper.IsNullOrEmpty(x.Status) && x.Status.Contains("ORDEM") && x.Status.Replace("ORDEM", "-").Split(new char[1] { '-' })[1].Trim().Equals($"{SelectedDocumento.Ordem}")).ToList(); } foreach (Item item in list) { await new ItemServico().Reativar(item, ""); } } public string GerarObs(Documento doc) { if (doc.Tipo != 0) { return $"CLIENTE: {doc.Controle.Cliente.Nome}{Environment.NewLine}CÓDIGO: {((DomainBase)doc).Id}{Environment.NewLine}PROPOSTA: {doc.Proposta}{Environment.NewLine}APÓLICE: {doc.Apolice}{Environment.NewLine}PROPOSTA DE ENDOSSO: {doc.PropostaEndosso}{Environment.NewLine}ENDOSSO: {doc.Endosso}"; } return $"CLIENTE: {doc.Controle.Cliente.Nome}{Environment.NewLine}CÓDIGO: {((DomainBase)doc).Id}{Environment.NewLine}PROPOSTA: {doc.Proposta}{Environment.NewLine}APÓLICE: {doc.Apolice}"; } public async Task RecusarApolice() { if (SelectedDocumento == null) { return; } bool[] array = await Funcoes.VerificarPagamento(((DomainBase)SelectedDocumento).Id); if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 23) && array.Any((bool x) => x)) { await ShowMessage("NÃO É POSSÍVEL RECURSAR UM APÓLICE ENQUANTO HOUVER RECEBIMENTO DE COMISSÃO OU PAGAMENTO DE VENDEDORES PARA A APÓLICE"); return; } bool flag = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 23) && array[1]; if (flag) { flag = await ShowMessage("EXISTEM PAGAMENTOS PARA OS VENDEDORES DO CONTRATO, DESEJA CRIAR ESTORNOS PARA ESSES PAGAMENTOS?", "SIM", "NÃO"); } bool estorno = flag; Documento val = await Servico.BuscarApoliceAsync(((DomainBase)DocumentoSelecionado).Id); IList list; if (val.Controle.Documentos.Count <= 1) { list = val.Controle.Documentos; } else { IList list2 = (from x in val.Controle.Documentos where !x.Excluido orderby x.Ordem select x).ToList(); list = list2; } IList list3 = list; if (list3.Count > 1 && ((DomainBase)list3.Last((Documento x) => (int)x.Situacao != 7)).Id != ((DomainBase)DocumentoSelecionado).Id) { await ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO ENQUANTO HOUVER ENDOSSOS EM CIMA DO MESMO."); return; } if ((int)val.Situacao == 7) { await ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO JÁ RECUSADO."); return; } string text = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? "A PROPOSTA SELECIONADA" : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? "A APÓLICE SELECIONADA" : "O ENDOSSO SELECIONADO")); if (await ShowMessage("DESEJA REALMENTE RECUSAR " + text + "? " + Environment.NewLine + "ESSE PROCEDIMENTO É IRREVERSÍVEL.", "SIM", "NÃO")) { string motivo = await ShowObservacaoDialog(); if (motivo != null) { Loading(isLoading: true); await Funcoes.RecusarApolice(SelectedDocumento, motivo, estorno); string text2 = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("A PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("A APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("A PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("O ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); RegistrarAcao("RECUSOU " + text2, ((DomainBase)SelectedDocumento).Id, (TipoTela)2, GerarObs(SelectedDocumento) + Environment.NewLine + "MOTIVO: " + motivo); Loading(isLoading: false); } } } public async Task IncluirEndosso() { if (!Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 13) && string.IsNullOrWhiteSpace(SelectedDocumento.Apolice)) { await ShowMessage("PROPOSTA NÃO PODE SER ENDOSSADA. NECESSÁRIO PREENCHER O NÚMERO DA APÓLICE E DATA DE EMISSÃO ANTES DE PROSSEGUIR."); return false; } ObservableCollection tipoEndossoList = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? new ObservableCollection(new List { (TipoEndosso)2, (TipoEndosso)1, (TipoEndosso)4 }) : new ObservableCollection(new List { (TipoEndosso)0, (TipoEndosso)1, (TipoEndosso)2, (TipoEndosso)4 })); if ((int)SelectedDocumento.Situacao == 3) { tipoEndossoList = new ObservableCollection(new List { (TipoEndosso)3 }); } TipoEndossoList = tipoEndossoList; Documento val = new Documento { Controle = SelectedDocumento.Controle, Tipo = 1, Ordem = SelectedDocumento.Controle.Documentos.Where((Documento x) => !x.Excluido).Max((Documento x) => x.Ordem) + 1, NegocioCorretora = (NegocioCorretora)(((int?)SelectedDocumento.NegocioCorretora) ?? (((int)SelectedDocumento.Situacao == 2 && SelectedDocumento.Negocio.HasValue && (int)SelectedDocumento.Negocio.GetValueOrDefault() == 1) ? 1 : 0)), Situacao = SelectedDocumento.Situacao, Negocio = SelectedDocumento.Negocio, TipoRecebimento = SelectedDocumento.TipoRecebimento, Vigencia1 = Funcoes.GetNetworkTime().Date, Vigencia2 = SelectedDocumento.Vigencia2, ApoliceConferida = false, PropostaAssinada = false, AdicionalComiss = false, Excluido = false, Apolice = SelectedDocumento.Apolice, Proposta = SelectedDocumento.Proposta, TipoEndosso = (TipoEndosso)(((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 2) ? 2 : 0), Comissao = SelectedDocumento.Comissao, Estipulante1 = SelectedDocumento.Estipulante1, Estipulante2 = SelectedDocumento.Estipulante2, Estipulante3 = SelectedDocumento.Estipulante3, Estipulante4 = SelectedDocumento.Estipulante4, Estipulante5 = SelectedDocumento.Estipulante5 }; SelectedParcela = null; SelectedDocumento = null; SelectedPagamento = null; if ((int)val.TipoRecebimento.GetValueOrDefault() == 1) { List list = (from x in Repasses.Where((VendedorParcela x) => (int)x.Parcela.SubTipo == 1).ToList() group x by ((DomainBase)x.Vendedor).Id).Select((Func, VendedorParcela>)((IGrouping x) => new VendedorParcela { Repasse = x.First().Repasse, Parcela = SelectedParcela, Documento = SelectedDocumento, ValorRepasse = default(decimal), Vendedor = x.First().Vendedor, PorcentagemRepasse = x.First().PorcentagemRepasse, TipoVendedor = x.First().TipoVendedor })).ToList(); Pagamentos = new ObservableCollection(list); Repasses = list; } else { Pagamentos = null; Repasses = null; } Parcelas = null; SelectedDocumento = val; NovaApolice = true; AllowEditVendedor = false; AllowEditApolice = true; IsEndosso = true; base.IsEnabledEditEndosso = true; base.EnableFields = true; base.EnableIncluir = false; AllowEditEmissao = true; Gestor.Application.Actions.Actions.EnableMainMenu?.Invoke(obj: false); return true; } public async void RecalculaRepasses() { if (Repasses == null) { return; } bool renovacao = (SelectedDocumento.NegocioCorretora.HasValue ? ((int)SelectedDocumento.NegocioCorretora.GetValueOrDefault() == 1) : ((int)SelectedDocumento.Situacao == 2 && SelectedDocumento.Negocio.HasValue && (int)SelectedDocumento.Negocio.GetValueOrDefault() == 1)); Repasses?.Where((VendedorParcela x) => NovaApolice || (int)x.Parcela.SubTipo == 1).ToList().ForEach(delegate(VendedorParcela x) { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Invalid comparison between Unknown and I4 //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Invalid comparison between Unknown and I4 if (x.Parcela == null || x.Repasse == null || x.DataPagamento.HasValue) { return; } Parcela parcela = x.Parcela; parcela.Documento = SelectedDocumento; decimal value = Funcoes.CalculaRepasse(x.Repasse, parcela); decimal value2; if (renovacao) { Repasse repasse = x.Repasse; if (repasse == null || (int)repasse.Tipo.GetValueOrDefault() != 3) { value2 = x.Repasse.ValorRenovacao; goto IL_008d; } } value2 = x.Repasse.ValorNovo; goto IL_008d; IL_008d: x.PorcentagemRepasse = value2; decimal? valorRepasse = (((int)x.Repasse.Forma.GetValueOrDefault() != 3) ? new decimal?(value) : (x.ValorTotal / (decimal?)SelectedDocumento.NumeroParcelas)); if (x.CoCorretagem) { decimal premioLiquido = SelectedDocumento.PremioLiquido; decimal? num = (SelectedDocumento.ComissaoTotal - (decimal?)SelectedDocumento.Comissao) / (decimal?)100; valorRepasse = (decimal?)premioLiquido * num; } x.ValorRepasse = valorRepasse; x.ValorTotal = value; }); if (NovaApolice) { Pagamentos = new ObservableCollection(Repasses.OrderBy((VendedorParcela x) => ((DomainBase)x.TipoVendedor).Id)); } else { await SelecionaParcela(SelectedParcela ?? Parcelas.FirstOrDefault()); CalculaComissao(SelectedDocumento, Parcelas); } } public void RecalculaRepasse() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 if ((!IsFatura && BaixarParcelas && (int)SelectedParcela.SubTipo == 1) || Repasses == null || Repasses.Count == 0) { return; } if (((DomainBase)SelectedParcela).Id == 0L) { Repasses.ForEach(delegate(VendedorParcela x) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Invalid comparison between Unknown and I4 if (x.DataPagamento.HasValue) { return; } Repasse repasse3 = x.Repasse; if (repasse3 != null && (int)repasse3.Tipo.GetValueOrDefault() == 3) { return; } Parcela val = x.Parcela ?? SelectedParcela; val.Documento = SelectedDocumento; if (x.Repasse != null) { x.Repasse.ValorNovo = x.PorcentagemRepasse ?? x.Repasse.ValorNovo; x.Repasse.ValorRenovacao = x.PorcentagemRepasse ?? x.Repasse.ValorRenovacao; } decimal value2 = Funcoes.CalculaRepasse(x.Repasse, val); decimal? valorRepasse2; if (SelectedDocumento.NumeroParcelas > 0m && !SelectedParcela.NumeroParcela.Equals(999)) { Repasse repasse4 = x.Repasse; if (repasse4 != null && (int)repasse4.Forma.GetValueOrDefault() == 3) { valorRepasse2 = x.ValorTotal / (decimal?)SelectedDocumento.NumeroParcelas; goto IL_015c; } } valorRepasse2 = value2; goto IL_015c; IL_015c: x.ValorRepasse = valorRepasse2; x.ValorTotal = value2; }); Pagamentos = new ObservableCollection(Repasses); return; } Repasses?.Where((VendedorParcela x) => ((DomainBase)SelectedParcela).Id > 0 && ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id).ToList().ForEach(delegate(VendedorParcela x) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Invalid comparison between Unknown and I4 //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Invalid comparison between Unknown and I4 //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Invalid comparison between Unknown and I4 if (x.DataPagamento.HasValue) { return; } Repasse repasse = x.Repasse; if (repasse != null && (int)repasse.Tipo.GetValueOrDefault() == 3) { return; } Parcela selectedParcela = SelectedParcela; selectedParcela.Documento = SelectedDocumento; if (x.Repasse != null) { x.Repasse.ValorNovo = x.PorcentagemRepasse ?? x.Repasse.ValorNovo; x.Repasse.ValorRenovacao = x.PorcentagemRepasse ?? x.Repasse.ValorRenovacao; } decimal value = Funcoes.CalculaRepasse(x.Repasse, selectedParcela); decimal? valorRepasse; if (SelectedDocumento.NumeroParcelas > 0m && !SelectedParcela.NumeroParcela.Equals(999)) { Repasse repasse2 = x.Repasse; if (repasse2 != null && (int)repasse2.Forma.GetValueOrDefault() == 3) { valorRepasse = x.ValorTotal / (decimal?)SelectedDocumento.NumeroParcelas; goto IL_0152; } } valorRepasse = value; goto IL_0152; IL_0152: x.ValorRepasse = valorRepasse; x.ValorTotal = (((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1 && (int)SelectedParcela.SubTipo == 1) ? new decimal?(value) : x.ValorTotal); }); Pagamentos = new ObservableCollection(Repasses?.Where((VendedorParcela x) => ((DomainBase)SelectedParcela).Id > 0 && ((DomainBase)x.Parcela).Id == ((DomainBase)SelectedParcela).Id).ToList()); } public async Task>> SalvarParcelas(int tipo) { if (SelectedParcela.Documento == null) { SelectedParcela.Documento = SelectedDocumento; } SelectedParcela.Documento.Parcelas = Parcelas; if ((int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() == 1 && (int)SelectedParcela.SubTipo == 1 && SelectedParcela.Comissao == 0m) { SelectedParcela.Comissao = SelectedDocumento.Comissao; } List> errors = SelectedParcela.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 9), Recursos.Configuracoes.Any((ConfiguracaoSistema y) => (int)y.Configuracao == 11), EditandoParcela, Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 16)); errors.AddRange(ValidaParcelaEspecial(tipo)); decimal num = ((SelectedParcela.ValorExtrato == 0m) ? SelectedParcela.ValorLiquidoFatura : SelectedParcela.ValorExtrato); int num2 = ((num > 0m) ? num.CompareTo(SelectedParcela.ValorComissao) : SelectedParcela.ValorComissao.CompareTo(num)); bool flag = errors.Count == 1 && 2 == (int)SelectedDocumento.TipoRecebimento.GetValueOrDefault() && num2 < 0; if (flag) { flag = await ShowMessage("VALOR RECEBIMENTO MAIOR QUE VALOR PARCELA, CONTINUAR?", "SIM", "NÃO"); } if (flag) { errors.Clear(); } if (errors.Count > 0) { return errors; } SelectedParcela.Baixando = false; if (!Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 5) && (SelectedParcela.Iss > 0m || SelectedParcela.Irr > 0m || SelectedParcela.Outros > 0m || SelectedParcela.Desconto > 0m)) { SelectedParcela.Iss = 0m; SelectedParcela.Irr = 0m; SelectedParcela.Outros = 0m; SelectedParcela.Desconto = 0m; SelectedParcela.ValorComDesconto = SelectedParcela.ValorComissao; } switch (tipo) { case 1: await AlterarVencimento(); break; case 2: await BaixarComissao(); break; case 3: case 4: await AdicionarParcelaEspecial(); break; } return null; } private List> ValidaParcelaEspecial(int tipo) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 List> list = new List>(); if (tipo == 4 && (int)SelectedParcela.SubTipo == 1) { list.Add(new KeyValuePair("SubTipo|TIPO", "A PARCELA ESPECIAL NÃO PODE SER DO TIPO PARCELA NORMAL")); } return list; } public Documento AbrirDetalhes() { Documento selectedDocumento = SelectedDocumento; selectedDocumento.Parcelas = Parcelas; selectedDocumento.Pagamentos = Repasses; return selectedDocumento; } public bool CompararValores() { if (((DomainBase)SelectedDocumento).Id != 0L && !((DomainBase)SelectedDocumento).HasChange("PremioLiquido") && !((DomainBase)SelectedDocumento).HasChange("PremioAdicional") && !((DomainBase)SelectedDocumento).HasChange("Comissao") && !((DomainBase)SelectedDocumento).HasChange("Iof")) { return ((DomainBase)SelectedDocumento).HasChange("AdicionalComiss"); } return true; } public Parcela AbrirDetalhesParcela() { Parcela selectedParcela = SelectedParcela; selectedParcela.Vendedores = Pagamentos; return selectedParcela; } public void ManutecaoItens() { if (Invoke) { Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)3, "Manutencao"); } } public async Task PagamentoVendedor(Parcela parcela) { return await ParcelaServico.TemPagamento(((DomainBase)parcela).Id); } public async Task ExcluirPagamento(VendedorParcela pagamento) { Loading(isLoading: true); if (await Funcoes.ExcluirPagamento(pagamento)) { ToggleSnackBar("PAGAMENTO EXCLUÍDO COM SUCESSO"); string text = ((SelectedDocumento.Tipo == 0 && string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA PROPOSTA \"" + SelectedDocumento.Proposta + "\"") : ((SelectedDocumento.Tipo == 0 && !string.IsNullOrEmpty(SelectedDocumento.Apolice)) ? ("NA APÓLICE \"" + SelectedDocumento.Apolice + "\"") : (string.IsNullOrEmpty(SelectedDocumento.Endosso) ? ("NA PROPOSTA DE ENDOSSO \"" + SelectedDocumento.PropostaEndosso + "\"") : ("NO ENDOSSO \"" + SelectedDocumento.Endosso + "\"")))); string descricao = "PAGAMENTO DO VENDEDOR " + pagamento.Vendedor.Nome + " EXCLUÍDO, " + text; RegistrarAcao(descricao, ((DomainBase)pagamento).Id, (TipoTela)37, $"{GerarObs(SelectedDocumento)}{Environment.NewLine}VENDEDOR: {pagamento.Vendedor.Nome}{Environment.NewLine}COMISSÃO TOTAL: {pagamento.ValorTotal:C2}"); } await CarregarParcelas(SelectedDocumento); await CarregaRepasse(((DomainBase)SelectedDocumento).Id); await SelecionaParcela(Parcelas.FirstOrDefault()); AllowEditApolice = Parcelas.Where((Parcela x) => (int)x.SubTipo == 1).All((Parcela x) => !x.DataRecebimento.HasValue) && Repasses.Where((VendedorParcela x) => (int)x.Parcela.SubTipo == 1).All((VendedorParcela x) => !x.DataPagamento.HasValue); BaixarParcelas = false; Loading(isLoading: false); } public async Task CarregarImposto() { List source = await new ImpostoServico().Buscar(true); object obj = ((IEnumerable)source).FirstOrDefault((Func)((Imposto x) => x.Seguradora != null && ((DomainBase)x.Seguradora).Id == ((DomainBase)SelectedDocumento.Controle.Seguradora).Id && x.Ramo != null && ((DomainBase)x.Ramo).Id == ((DomainBase)SelectedDocumento.Controle.Ramo).Id)) ?? ((IEnumerable)source).FirstOrDefault((Func)((Imposto x) => x.Seguradora != null && ((DomainBase)x.Seguradora).Id == ((DomainBase)SelectedDocumento.Controle.Seguradora).Id && x.Ramo == null)); if (obj == null) { obj = ((IEnumerable)source).FirstOrDefault((Func)((Imposto x) => x.Seguradora == null && x.Ramo != null && ((DomainBase)x.Ramo).Id == ((DomainBase)SelectedDocumento.Controle.Ramo).Id)); } if (obj == null) { obj = ((IEnumerable)source).FirstOrDefault((Func)((Imposto x) => x.Seguradora == null && x.Ramo == null)); } Imposto val = (Imposto)obj; Imposto = (Imposto)(((object)val) ?? ((object)new Imposto())); } public async Task EditarParcelas() { if (DocumentoSelecionado == null) { DocumentoSelecionado = SelectedDocumento; } await ShowEditarParcelasDialog(DocumentoSelecionado); await CarregarParcelas(DocumentoSelecionado); } public async void AbrirLogAntigo() { Loading(isLoading: true); string text = await Servico.BuscarLogAntigo(((DomainBase)SelectedDocumento).Id); Loading(isLoading: false); if (string.IsNullOrEmpty(text)) { await ShowMessage("NÃO HÁ LOG PARA ESSE DOCUMENTO"); } else { ShowDrawer(new LogSistemaAntigo(((DomainBase)SelectedDocumento).Id, text), 0, close: false); } } public async void AbrirLogAntigoParcela() { Loading(isLoading: true); string log = ""; foreach (Parcela item in await ParcelaServico.BuscarParcelas(((DomainBase)SelectedDocumento).Id)) { string text = log; log = text + await ParcelaServico.BuscarLogAntigo(((DomainBase)item).Id); } Loading(isLoading: false); if (string.IsNullOrEmpty(log)) { await ShowMessage("NÃO HÁ LOG PARA PARCELAS"); } else { ShowDrawer(new LogSistemaAntigo(((DomainBase)SelectedDocumento).Id, log), 0, close: false); } } public async Task AjusteComissãoCoCorretagem(bool removido = false) { try { if (removido) { Documento selectedDocumento = SelectedDocumento; Documento selectedDocumento2 = SelectedDocumento; selectedDocumento.Comissao = ((selectedDocumento2 != null) ? selectedDocumento2.ComissaoTotal : null).GetValueOrDefault(); SelectedDocumento = await Servico.Save(SelectedDocumento, updateParcelas: false, criarParcelas: false); AjustaParcelasCoCorretagem(); CalculaComissao(SelectedDocumento, Parcelas); } else { VendedorParcela selectedPagamento = SelectedPagamento; decimal num = ((selectedPagamento != null) ? selectedPagamento.Repasse.ValorNovo : 0m); decimal comissao = SelectedDocumento.Comissao; SelectedDocumento.ComissaoTotal = comissao; SelectedDocumento.Comissao = Math.Round(comissao - comissao * (num * 0.01m), 2); SelectedDocumento = await Servico.Save(SelectedDocumento, updateParcelas: false, criarParcelas: false); AjustaParcelasCoCorretagem(); CalculaComissao(SelectedDocumento, Parcelas); } } catch { await ShowMessage("NÃO FOI POSSÍVEL ALTERAR A COMISSÃO DA CO-CORRETAGEM"); } } public async void AjustaParcelasCoCorretagem() { try { ObservableCollection parcelas = Parcelas; foreach (Parcela item in parcelas) { if (item.NumeroParcela == 999) { return; } item.Comissao = SelectedDocumento.Comissao; } Parcelas = new ObservableCollection(await ParcelaServico.SaveRange(parcelas.ToList())); await CarregarParcelas(SelectedDocumento); } catch { await ShowMessage("NÃO FOI POSSÍVEL SALVAR AS PARCELAS"); } } public List VendedorCoCorretagem(bool coCorretagem = false) { if (coCorretagem) { return Vendedores = Vendedores.Where((Vendedor vendedor) => RepassesVendedores?.FindAll((Repasse repasse) => ((DomainBase)repasse.Vendedor).Id == ((DomainBase)vendedor).Id).Any((Repasse x) => (int)x.Tipo.GetValueOrDefault() == 3) ?? false).ToList(); } return Vendedores = (from vendedor in Recursos.Vendedores where vendedor.Ativo && !vendedor.Corretora && vendedor.IdEmpresa == Recursos.Usuario.IdEmpresa select vendedor into v orderby v.Nome select v).ToList(); } }