From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../ViewModels/Generic/BaseApoliceViewModel.cs | 6893 ++++++++++++++++++++ 1 file changed, 6893 insertions(+) create mode 100644 Gestor.Application/ViewModels/Generic/BaseApoliceViewModel.cs (limited to 'Gestor.Application/ViewModels/Generic/BaseApoliceViewModel.cs') diff --git a/Gestor.Application/ViewModels/Generic/BaseApoliceViewModel.cs b/Gestor.Application/ViewModels/Generic/BaseApoliceViewModel.cs new file mode 100644 index 0000000..5bb2e93 --- /dev/null +++ b/Gestor.Application/ViewModels/Generic/BaseApoliceViewModel.cs @@ -0,0 +1,6893 @@ +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; +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; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows; + +namespace Gestor.Application.ViewModels.Generic +{ + public class BaseApoliceViewModel : BaseSegurosViewModel + { + internal ApoliceServico Servico; + + internal Gestor.Application.Servicos.Seguros.PerfilServico PerfilServico; + + internal Gestor.Application.Servicos.Ferramentas.RamoServico RamoServico; + + internal Gestor.Application.Servicos.Ferramentas.SeguradoraServico SeguradoraServico; + + internal Gestor.Application.Servicos.Ferramentas.VendedorServico VendedorServico; + + internal Gestor.Application.Servicos.ParcelaServico ParcelaServico; + + internal Gestor.Application.Servicos.Ferramentas.ProdutoServico ProdutoServico; + + internal Gestor.Application.Servicos.Ferramentas.EstipulanteServico EstipulanteServico; + + internal Gestor.Application.Servicos.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.Collapsed; + + private Visibility _visibilityReplicarFatura = Visibility.Collapsed; + + 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() + { + 1, + 2, + 5 + }); + + private ObservableCollection _tipoEndosso = new ObservableCollection(new List() + { + 0, + 1, + 2, + 4, + 3 + }); + + private Parcela _selectedParcela; + + private bool _coCorretagem; + + private Visibility _baixarParcelaVisibility = Visibility.Collapsed; + + private ObservableCollection _parcelas; + + private decimal _gerada; + + private decimal _comissOriginal; + + private Visibility _comissOriginalVisibility = Visibility.Collapsed; + + 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.Collapsed; + + 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; + + 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; + + private bool _alteracaoEnabled; + + private bool _allowEditEmissao; + + private bool _allowEditApolice; + + private bool _allowVigenciaFinal; + + private bool _novaApolice; + + private bool _renovar; + + public decimal Tolerancia; + + private bool _enableRepasse; + + private bool _bloquearObservacao; + + private string _editarParcelasLabel; + + private string _anotacoes; + + private int _quantidadeFaturas; + + private double _tamanhoGrid; + + private bool _inclusao; + + private bool _criandoParcelaEspecial; + + private bool _visibilityLogAntigo; + + public AcessoApolice Acesso + { + get; + set; + } + + public bool AllowEditApolice + { + get + { + return this._allowEditApolice; + } + set + { + this._allowEditApolice = value; + this.AllowVigenciaFinal = (value ? true : this.IsFatura); + base.OnPropertyChanged("AllowEditApolice"); + } + } + + public bool AllowEditEmissao + { + get + { + return this._allowEditEmissao; + } + set + { + this._allowEditEmissao = value; + base.OnPropertyChanged("AllowEditEmissao"); + } + } + + public bool AllowEditVendedor + { + get + { + return this._allowEditVendedor; + } + set + { + this._allowEditVendedor = this._incluirPermissEnabled & value; + base.OnPropertyChanged("AllowEditVendedor"); + } + } + + public bool AllowVigenciaFinal + { + get + { + return this._allowVigenciaFinal; + } + set + { + this._allowVigenciaFinal = value; + base.OnPropertyChanged("AllowVigenciaFinal"); + } + } + + public bool AlteracaoEnabled + { + get + { + return this._alteracaoEnabled; + } + set + { + this._alteracaoEnabled = value; + base.OnPropertyChanged("AlteracaoEnabled"); + } + } + + public new string Anotacoes + { + get + { + return this._anotacoes; + } + set + { + this._anotacoes = value; + base.OnPropertyChanged("Anotacoes"); + } + } + + public bool Apelido + { + get + { + return this._apelido; + } + set + { + this._apelido = value; + base.OnPropertyChanged("Apelido"); + } + } + + public string Assinada + { + get + { + return this._assinada; + } + set + { + this._assinada = value; + base.OnPropertyChanged("Assinada"); + } + } + + public bool BaixarParcelas + { + get + { + return this._baixarParcelas; + } + set + { + this._baixarParcelas = value; + base.OnPropertyChanged("BaixarParcelas"); + } + } + + public Visibility BaixarParcelaVisibility + { + get + { + return this._baixarParcelaVisibility; + } + set + { + if (base.Restricao(15)) + { + return; + } + this._baixarParcelaVisibility = value; + base.OnPropertyChanged("BaixarParcelaVisibility"); + } + } + + public bool BloquearObservacao + { + get + { + return this._bloquearObservacao; + } + set + { + this._bloquearObservacao = value; + base.OnPropertyChanged("BloquearObservacao"); + } + } + + public bool BotoesParcelaEnabled + { + get + { + return this._botoesParcelaEnabled; + } + set + { + this._botoesParcelaEnabled = value; + base.OnPropertyChanged("BotoesParcelaEnabled"); + } + } + + public bool CoCorretagem + { + get + { + return this._coCorretagem; + } + set + { + if (this.SelectedPagamento != null) + { + this.SelectedPagamento.set_CoCorretagem(value); + } + this._coCorretagem = value; + base.OnPropertyChanged("CoCorretagem"); + } + } + + public string CodigoDocumento + { + get + { + return this._codigoDocumento; + } + set + { + this._codigoDocumento = value; + base.OnPropertyChanged("CodigoDocumento"); + } + } + + public decimal ComissOriginal + { + get + { + return this._comissOriginal; + } + set + { + this.ComissOriginalVisibility = (this.VerificaCoCorretagem() ? Visibility.Visible : Visibility.Collapsed); + this._comissOriginal = value; + base.OnPropertyChanged("ComissOriginal"); + } + } + + public Visibility ComissOriginalVisibility + { + get + { + return this._comissOriginalVisibility; + } + set + { + this._comissOriginalVisibility = value; + base.OnPropertyChanged("ComissOriginalVisibility"); + } + } + + public string Conferida + { + get + { + return this._conferida; + } + set + { + this._conferida = value; + base.OnPropertyChanged("Conferida"); + } + } + + public bool ControleAdm + { + get + { + return this._controleAdm; + } + set + { + this._controleAdm = value; + base.OnPropertyChanged("ControleAdm"); + } + } + + public bool CriandoParcelaEspecial + { + get + { + return this._criandoParcelaEspecial; + } + set + { + this._criandoParcelaEspecial = value; + } + } + + private Documento DocumentoRenovado + { + get; + set; + } + + internal Documento DocumentoSelecionado + { + get; + set; + } + + public bool EditandoParcela + { + get + { + return this._editandoParcela; + } + set + { + this._editandoParcela = value; + base.OnPropertyChanged("EditandoParcela"); + } + } + + public string EditarParcelasLabel + { + get + { + return this._editarParcelasLabel; + } + set + { + this._editarParcelasLabel = value; + base.OnPropertyChanged("EditarParcelasLabel"); + } + } + + public string Emissao + { + get + { + return this._emissao; + } + set + { + this._emissao = value; + base.OnPropertyChanged("Emissao"); + } + } + + public DateTime? EmissaoDocumento + { + get + { + return this._emissaoDocumento; + } + set + { + this._emissaoDocumento = value; + base.OnPropertyChanged("EmissaoDocumento"); + } + } + + public bool EnableAlterarSituacao + { + get + { + return this._enableAlterarSituacao; + } + set + { + this._enableAlterarSituacao = value; + base.OnPropertyChanged("EnableAlterarSituacao"); + } + } + + public bool EnableControle + { + get + { + return this._enableControle; + } + set + { + this._enableControle = value; + base.OnPropertyChanged("EnableControle"); + } + } + + public bool EnableRepasse + { + get + { + return this._enableRepasse; + } + set + { + this._enableRepasse = value; + base.OnPropertyChanged("EnableRepasse"); + } + } + + public List Estipulantes + { + get + { + return this._estipulantes; + } + set + { + this._estipulantes = value; + base.OnPropertyChanged("Estipulantes"); + } + } + + public string ExcluirParcelaLabel + { + get + { + return this._excluirParcelaLabel; + } + set + { + this._excluirParcelaLabel = value; + base.OnPropertyChanged("ExcluirParcelaLabel"); + } + } + + public decimal Gerada + { + get + { + return this._gerada; + } + set + { + this._gerada = value; + base.OnPropertyChanged("Gerada"); + } + } + + public string Importado + { + get + { + return this._importado; + } + set + { + this._importado = value; + base.OnPropertyChanged("Importado"); + } + } + + public Gestor.Model.Domain.Ferramentas.Imposto Imposto + { + get; + set; + } + + public bool Inclusao + { + get + { + return this._inclusao; + } + set + { + this._inclusao = value; + base.OnPropertyChanged("Inclusao"); + } + } + + public bool Invoke + { + get + { + return this._invoke; + } + set + { + this._invoke = value; + base.OnPropertyChanged("Invoke"); + } + } + + public bool IsEnableSituacao + { + get + { + return this._isEnableSituacao; + } + set + { + this._isEnableSituacao = value; + base.OnPropertyChanged("IsEnableSituacao"); + } + } + + public bool IsEndosso + { + get + { + return this._isEndosso; + } + set + { + this._isEndosso = value; + this.WorkOnSelectedTipo(value); + base.OnPropertyChanged("IsEndosso"); + } + } + + public bool IsFatura + { + get + { + return this._isFatura; + } + set + { + this._isFatura = value; + base.OnPropertyChanged("IsFatura"); + } + } + + public Visibility IsRenovacaoVisibility + { + get + { + return this._isRenovacaoVisibility; + } + set + { + this._isRenovacaoVisibility = value; + base.OnPropertyChanged("IsRenovacaoVisibility"); + } + } + + public bool Loaded + { + get; + set; + } + + public bool NovaApolice + { + get + { + return this._novaApolice; + } + set + { + this._novaApolice = value; + base.OnPropertyChanged("NovaApolice"); + } + } + + public ObservableCollection Pagamentos + { + get + { + return this._pagamentos; + } + set + { + this._pagamentos = value; + base.OnPropertyChanged("Pagamentos"); + } + } + + public ObservableCollection Parcelas + { + get + { + return this._parcelas; + } + set + { + this._parcelas = value; + if (value != null && value.Count == 0) + { + this.VisibilityExcluirParcela = Visibility.Collapsed; + this.VisibilityReplicarFatura = Visibility.Collapsed; + this.BaixarParcelaVisibility = Visibility.Collapsed; + this.VisibilityAlterarVencimento = Visibility.Collapsed; + } + base.OnPropertyChanged("Parcelas"); + } + } + + internal long ParcelaSelecionada + { + get; + set; + } + + public decimal Pendente + { + get + { + return this._pendente; + } + set + { + this._pendente = value; + base.OnPropertyChanged("Pendente"); + } + } + + public List Produtos + { + get + { + return this._produtos; + } + set + { + this._produtos = value; + base.OnPropertyChanged("Produtos"); + } + } + + public int QuantidadeFaturas + { + get + { + return this._quantidadeFaturas; + } + set + { + if (value < 0) + { + value = 0; + } + if (value > 12) + { + value = 12; + } + this._quantidadeFaturas = value; + base.OnPropertyChanged("QuantidadeFaturas"); + } + } + + public List Ramos + { + get + { + return this._ramos; + } + set + { + this._ramos = value; + base.OnPropertyChanged("Ramos"); + } + } + + public decimal Recebida + { + get + { + return this._recebida; + } + set + { + this._recebida = value; + base.OnPropertyChanged("Recebida"); + } + } + + public Visibility RecusaVisibility + { + get + { + return this._recusaVisibility; + } + set + { + this._recusaVisibility = (!base.Restricao(18) ? value : Visibility.Collapsed); + base.OnPropertyChanged("RecusaVisibility"); + } + } + + public bool Renovar + { + get + { + return this._renovar; + } + set + { + this._renovar = value; + base.OnPropertyChanged("Renovar"); + } + } + + public decimal Repasse + { + get + { + return this._repasse; + } + set + { + this._repasse = value; + base.OnPropertyChanged("Repasse"); + } + } + + public List Repasses + { + get + { + return this._repasses; + } + set + { + this._repasses = value; + base.OnPropertyChanged("Repasses"); + } + } + + public List RepassesVendedor + { + get + { + return this._repassesVendedor; + } + set + { + this._repassesVendedor = value; + this.EnableRepasse = (value == null ? false : value.Count > 0); + base.OnPropertyChanged("RepassesVendedor"); + } + } + + public List RepassesVendedores + { + get + { + return this._repassesVendedores; + } + set + { + this._repassesVendedores = value; + base.OnPropertyChanged("RepassesVendedores"); + } + } + + public List Seguradoras + { + get + { + return this._seguradoras; + } + set + { + this._seguradoras = value; + base.OnPropertyChanged("Seguradoras"); + } + } + + public List SeguradorasAnteriores + { + get + { + return this._seguradorasAnteriores; + } + set + { + this._seguradorasAnteriores = value; + base.OnPropertyChanged("SeguradorasAnteriores"); + } + } + + public Documento SelectedDocumento + { + get + { + return this._selectedDocumento; + } + set + { + DateTime networkTime; + long? nullable; + bool flag; + DateTime? emissao; + DateTime? remessa; + Visibility visibility; + long? nullable1; + string apolice; + if (value != null && value.get_Id() == 0) + { + this.VisibilityLogAntigo = false; + } + this._selectedDocumento = value; + this.Anotacoes = string.Empty; + base.EnableButtons = (value == null ? false : value.get_Id() > (long)0); + base.EnableIncluir = (value == null ? true : value.get_Id() > (long)0); + bool flag1 = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 13); + if (value == null || value.get_Id() <= (long)0) + { + flag = false; + } + else if (flag1) + { + flag = true; + } + else + { + flag = (string.IsNullOrWhiteSpace(value.get_Apolice()) || string.IsNullOrWhiteSpace(value.get_Proposta()) ? false : value.get_Emissao().HasValue); + } + base.EnableEndossar = flag; + base.EnableRenovar = (value == null || value.get_Id() <= (long)0 || !value.get_Vigencia2().HasValue ? false : !string.IsNullOrWhiteSpace(value.get_Apolice())); + if (value == null || value.get_Id() == 0) + { + this.ZeraComissao(); + } + this.CodigoDocumento = (this.SelectedDocumento == null || this.SelectedDocumento.get_Id() == 0 ? "" : string.Format("{0}", this.SelectedDocumento.get_Id())); + if (value != null && value.get_Status() == null && this.Status.First().get_Nome() == "SEM STATUS") + { + value.set_Status(this.Status.First()); + } + if (value == null || !value.get_Emissao().HasValue) + { + networkTime = Funcoes.GetNetworkTime(); + emissao = new DateTime?(networkTime.Date); + } + else + { + emissao = value.get_Emissao(); + } + this.EmissaoDocumento = emissao; + if (value == null || !value.get_Remessa().HasValue) + { + networkTime = Funcoes.GetNetworkTime(); + remessa = new DateTime?(networkTime.Date); + } + else + { + remessa = value.get_Remessa(); + } + this.TransmissaoDocumento = remessa; + if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 19)) + { + if (value != null) + { + apolice = value.get_Apolice(); + } + else + { + apolice = null; + } + if (string.IsNullOrWhiteSpace(apolice) || !value.get_Emissao().HasValue) + { + visibility = Visibility.Visible; + this.RecusaVisibility = visibility; + if (value != null) + { + nullable1 = new long?(value.get_Id()); + } + else + { + nullable = null; + nullable1 = nullable; + } + base.VerificarEnables(nullable1); + base.OnPropertyChanged("SelectedDocumento"); + return; + } + visibility = Visibility.Collapsed; + this.RecusaVisibility = visibility; + if (value != null) + { + nullable1 = new long?(value.get_Id()); + } + else + { + nullable = null; + nullable1 = nullable; + } + base.VerificarEnables(nullable1); + base.OnPropertyChanged("SelectedDocumento"); + return; + } + visibility = Visibility.Visible; + this.RecusaVisibility = visibility; + if (value != null) + { + nullable1 = new long?(value.get_Id()); + } + else + { + nullable = null; + nullable1 = nullable; + } + base.VerificarEnables(nullable1); + base.OnPropertyChanged("SelectedDocumento"); + } + } + + public VendedorParcela SelectedPagamento + { + get + { + return this._selectedPagamento; + } + set + { + this._selectedPagamento = value; + base.OnPropertyChanged("SelectedPagamento"); + } + } + + public Parcela SelectedParcela + { + get + { + return this._selectedParcela; + } + set + { + this._selectedParcela = value; + this.WorkOnSelectedParcela(value); + base.OnPropertyChanged("SelectedParcela"); + } + } + + public ObservableCollection Situacao + { + get + { + return this._situacao; + } + set + { + this._situacao = value; + base.OnPropertyChanged("Situacao"); + } + } + + public List Status + { + get + { + return this._status; + } + set + { + if (value.All((Gestor.Model.Domain.Seguros.Status x) => x.get_Nome() != "SEM STATUS")) + { + Gestor.Model.Domain.Seguros.Status statu = new Gestor.Model.Domain.Seguros.Status(); + statu.set_Nome("SEM STATUS"); + statu.set_Id((long)0); + statu.set_Ativo(true); + value.Insert(0, statu); + } + this._status = value; + base.OnPropertyChanged("Status"); + } + } + + public double TamanhoGrid + { + get + { + return this._tamanhoGrid; + } + set + { + this._tamanhoGrid = value; + base.OnPropertyChanged("TamanhoGrid"); + } + } + + public ObservableCollection TipoEndossoList + { + get + { + return this._tipoEndosso; + } + set + { + this._tipoEndosso = value; + base.OnPropertyChanged("TipoEndossoList"); + } + } + + public List TiposVendedor + { + get + { + return this._tiposVendedor; + } + set + { + this._tiposVendedor = value; + base.OnPropertyChanged("TiposVendedor"); + } + } + + public List TodosVendedores + { + get + { + return this._todosVendedores; + } + set + { + this._todosVendedores = value; + base.OnPropertyChanged("TodosVendedores"); + } + } + + public string Transmissao + { + get + { + return this._transmissao; + } + set + { + this._transmissao = value; + base.OnPropertyChanged("Transmissao"); + } + } + + public DateTime? TransmissaoDocumento + { + get + { + return this._transmissaoDocumento; + } + set + { + this._transmissaoDocumento = value; + base.OnPropertyChanged("TransmissaoDocumento"); + } + } + + public bool UltimaFatura + { + get + { + return this._ultimaFatura; + } + set + { + this._ultimaFatura = value; + base.OnPropertyChanged("UltimaFatura"); + } + } + + public List Vendedores + { + get + { + return this._vendedores; + } + set + { + this._vendedores = value; + base.OnPropertyChanged("Vendedores"); + } + } + + public Visibility VisibilityAlterarVencimento + { + get + { + return this._visibilityAlterarVencimento; + } + set + { + this._visibilityAlterarVencimento = value; + base.OnPropertyChanged("VisibilityAlterarVencimento"); + } + } + + public Visibility VisibilityExcluirParcela + { + get + { + return this._visibilityExcluirParcela; + } + set + { + this._visibilityExcluirParcela = value; + base.OnPropertyChanged("VisibilityExcluirParcela"); + } + } + + public bool VisibilityLogAntigo + { + get + { + return this._visibilityLogAntigo; + } + set + { + this._visibilityLogAntigo = value; + base.OnPropertyChanged("VisibilityLogAntigo"); + } + } + + public Visibility VisibilityReplicarFatura + { + get + { + return this._visibilityReplicarFatura; + } + set + { + this._visibilityReplicarFatura = value; + base.OnPropertyChanged("VisibilityReplicarFatura"); + } + } + + public BaseApoliceViewModel() + { + this._invoke = true; + this._enableControle = true; + this._visibilityExcluirParcela = Visibility.Collapsed; + this._visibilityReplicarFatura = Visibility.Collapsed; + this._importado = "CLIQUE PARA VER INFORMAÇÕES SOBRE A INCLUSÃO"; + this._botoesParcelaEnabled = true; + this._situacao = new ObservableCollection(new List() + { + 1, + 2, + 5 + }); + this._tipoEndosso = new ObservableCollection(new List() + { + 0, + 1, + 2, + 4, + 3 + }); + this._baixarParcelaVisibility = Visibility.Collapsed; + this._comissOriginalVisibility = Visibility.Collapsed; + this._excluirParcelaLabel = "EXCLUIR BAIXA"; + this._produtos = Recursos.Produtos; + this._status = Recursos.Status; + this._isRenovacaoVisibility = Visibility.Collapsed; + this._assinada = "PROPOSTA ASSINADA"; + this._conferida = "APÓLICE CONFERIDA"; + this._transmissao = "TRANSMISSÃO DE PROPOSTA"; + this._emissao = "EMISSÃO DA APÓLICE"; + List tipoVendedor = Recursos.TipoVendedor; + if (tipoVendedor != null) + { + list = tipoVendedor.Where((TipoVendedor x) => { + if (!x.get_Ativo().HasValue) + { + return true; + } + return x.get_Ativo().Value; + }).ToList(); + } + else + { + list = null; + } + this._tiposVendedor = list; + this._allowEditVendedor = true; + this._alteracaoEnabled = true; + this._allowEditEmissao = true; + this._allowEditApolice = true; + this._allowVigenciaFinal = true; + this._bloquearObservacao = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 39); + this._editarParcelasLabel = "EDITAR PARCELAS"; + this._visibilityLogAntigo = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 22); + base(); + List list; + this.Servico = new ApoliceServico(); + this.VendedorServico = new Gestor.Application.Servicos.Ferramentas.VendedorServico(); + this.ParcelaServico = new Gestor.Application.Servicos.ParcelaServico(); + this.RamoServico = new Gestor.Application.Servicos.Ferramentas.RamoServico(); + this.SeguradoraServico = new Gestor.Application.Servicos.Ferramentas.SeguradoraServico(); + this.ProdutoServico = new Gestor.Application.Servicos.Ferramentas.ProdutoServico(); + this.EstipulanteServico = new Gestor.Application.Servicos.Ferramentas.EstipulanteServico(); + this.TarefaServico = new Gestor.Application.Servicos.TarefaServico(); + this.PerfilServico = new Gestor.Application.Servicos.Seguros.PerfilServico(); + this.Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 6); + this.ControleAdm = (Recursos.Configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 33) ? true : Recursos.Usuario.get_Administrador()); + } + + public Documento AbrirDetalhes() + { + Documento selectedDocumento = this.SelectedDocumento; + selectedDocumento.set_Parcelas(this.Parcelas); + selectedDocumento.set_Pagamentos(this.Repasses); + return selectedDocumento; + } + + public Parcela AbrirDetalhesParcela() + { + Parcela selectedParcela = this.SelectedParcela; + selectedParcela.set_Vendedores(this.Pagamentos); + return selectedParcela; + } + + public async void AbrirLogAntigo() + { + base.Loading(true); + string str = await this.Servico.BuscarLogAntigo(this.SelectedDocumento.get_Id()); + base.Loading(false); + if (!string.IsNullOrEmpty(str)) + { + base.ShowDrawer(new LogSistemaAntigo(this.SelectedDocumento.get_Id(), str), 0, false); + } + else + { + await base.ShowMessage("NÃO HÁ LOG PARA ESSE DOCUMENTO", "OK", "", false); + } + } + + public async void AbrirLogAntigoParcela() + { + base.Loading(true); + string str = ""; + foreach (Parcela parcela in await this.ParcelaServico.BuscarParcelas(this.SelectedDocumento.get_Id())) + { + string str1 = str; + string str2 = await this.ParcelaServico.BuscarLogAntigo(parcela.get_Id()); + str = string.Concat(str1, str2); + str1 = null; + } + base.Loading(false); + if (!string.IsNullOrEmpty(str)) + { + base.ShowDrawer(new LogSistemaAntigo(this.SelectedDocumento.get_Id(), str), 0, false); + } + else + { + await base.ShowMessage("NÃO HÁ LOG PARA PARCELAS", "OK", "", false); + } + str = null; + } + + public async Task AdicionarParcelaEspecial() + { + long num; + DateTime? nullable; + DateTime valueOrDefault; + string str; + long num1; + DateTime? nullable1; + DateTime? nullable2; + DateTime? nullable3; + DateTime? nullable4; + DateTime? nullable5; + DateTime? nullable6; + string str1; + string str2; + string str3; + if (this.SelectedParcela != null && !this.CriandoParcelaEspecial) + { + this.CriandoParcelaEspecial = true; + if (this.SelectedPagamento == null || this.SelectedPagamento.get_Vendedor().get_Corretora()) + { + this.SelectedPagamento = this.PropriaCorretora(); + } + else + { + List> keyValuePairs = await this.AdicionarVendedorParcelaEspecial(); + if (keyValuePairs.Count > 0) + { + this._criandoParcelaEspecial = false; + await base.ShowMessage(keyValuePairs, " PROCESSO INTERROMPIDO, PARCELA/FATURA SEM VENDENDEDOR", "OK", ""); + return; + } + } + this.SelectedParcela.set_Documento(this.SelectedDocumento); + DateTime vencimento = this.SelectedParcela.get_Vencimento(); + DateTime? dataRecebimento = this.SelectedParcela.get_DataRecebimento(); + DateTime? dataCredito = this.SelectedParcela.get_DataCredito(); + DateTime? dataControle = this.SelectedParcela.get_DataControle(); + int numeroParcela = this.SelectedParcela.get_NumeroParcela(); + DateTime? vigenciaIncial = this.SelectedParcela.get_VigenciaIncial(); + DateTime? vigenciaFinal = this.SelectedParcela.get_VigenciaFinal(); + DateTime? emissao = this.SelectedParcela.get_Emissao(); + str = (string.IsNullOrWhiteSpace(Gestor.Common.Validation.ValidationHelper.OnlyNumber(this.SelectedParcela.get_Fatura())) ? "1" : Gestor.Common.Validation.ValidationHelper.OnlyNumber(this.SelectedParcela.get_Fatura())); + num1 = (long.TryParse(str, out num) ? num : (long)1); + long num2 = num1; + if (this.QuantidadeFaturas == 0 || !this.IsFatura) + { + this.QuantidadeFaturas = 1; + } + if (this.QuantidadeFaturas <= 12) + { + for (int i = 0; i < this.QuantidadeFaturas; i++) + { + this.SelectedParcela.set_Vencimento(vencimento.AddMonths(i)); + Parcela selectedParcela = this.SelectedParcela; + ref Nullable nullablePointer = ref vigenciaIncial; + if (nullablePointer.HasValue) + { + valueOrDefault = nullablePointer.GetValueOrDefault(); + nullable1 = new DateTime?(valueOrDefault.AddMonths(i)); + } + else + { + nullable = null; + nullable1 = nullable; + } + selectedParcela.set_VigenciaIncial(nullable1); + Parcela parcela = this.SelectedParcela; + ref Nullable nullablePointer1 = ref vigenciaFinal; + if (nullablePointer1.HasValue) + { + valueOrDefault = nullablePointer1.GetValueOrDefault(); + nullable2 = new DateTime?(valueOrDefault.AddMonths(i)); + } + else + { + nullable = null; + nullable2 = nullable; + } + parcela.set_VigenciaFinal(nullable2); + Parcela selectedParcela1 = this.SelectedParcela; + ref Nullable nullablePointer2 = ref emissao; + if (nullablePointer2.HasValue) + { + valueOrDefault = nullablePointer2.GetValueOrDefault(); + nullable3 = new DateTime?(valueOrDefault.AddMonths(i)); + } + else + { + nullable = null; + nullable3 = nullable; + } + selectedParcela1.set_Emissao(nullable3); + Parcela parcela1 = this.SelectedParcela; + ref Nullable nullablePointer3 = ref dataRecebimento; + if (nullablePointer3.HasValue) + { + valueOrDefault = nullablePointer3.GetValueOrDefault(); + nullable4 = new DateTime?(valueOrDefault.AddMonths(i)); + } + else + { + nullable = null; + nullable4 = nullable; + } + parcela1.set_DataRecebimento(nullable4); + Parcela selectedParcela2 = this.SelectedParcela; + ref Nullable nullablePointer4 = ref dataCredito; + if (nullablePointer4.HasValue) + { + valueOrDefault = nullablePointer4.GetValueOrDefault(); + nullable5 = new DateTime?(valueOrDefault.AddMonths(i)); + } + else + { + nullable = null; + nullable5 = nullable; + } + selectedParcela2.set_DataCredito(nullable5); + Parcela parcela2 = this.SelectedParcela; + ref Nullable nullablePointer5 = ref dataControle; + if (nullablePointer5.HasValue) + { + valueOrDefault = nullablePointer5.GetValueOrDefault(); + nullable6 = new DateTime?(valueOrDefault.AddMonths(i)); + } + else + { + nullable = null; + nullable6 = nullable; + } + parcela2.set_DataControle(nullable6); + this.SelectedParcela.set_NumeroParcela(numeroParcela + i); + if (i > 0) + { + num2 += (long)1; + this.SelectedParcela.set_Fatura(string.Format("{0}", num2)); + nullable = null; + this.SelectedParcela.set_DataQuitacao(nullable); + } + List repasses = this.Repasses; + if (repasses != null) + { + repasses.ForEach((VendedorParcela x) => { + if (x.get_Repasse() == null) + { + return; + } + if (x.get_Repasse().get_Forma().GetValueOrDefault() == 1) + { + x.set_DataPrePagamento(this.SelectedParcela.get_DataRecebimento()); + } + x.set_Parcela(this.SelectedParcela); + BaseRepasse? @base = x.get_Repasse().get_Base(); + if (@base.HasValue) + { + switch (@base.GetValueOrDefault()) + { + case 1: + { + x.set_DataPrePagamento((this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? x.get_Parcela().get_VigenciaIncial() : new DateTime?(this.SelectedDocumento.get_Vigencia1()))); + return; + } + case 2: + { + x.set_DataPrePagamento(x.get_Parcela().get_DataCriacao()); + return; + } + case 3: + { + x.set_DataPrePagamento(new DateTime?((x.get_Parcela().get_Vencimento() == DateTime.MinValue ? this.SelectedDocumento.get_Vigencia1() : x.get_Parcela().get_Vencimento()))); + return; + } + case 4: + { + x.set_DataPrePagamento((this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? x.get_Parcela().get_Emissao() : this.SelectedDocumento.get_Emissao())); + return; + } + case 5: + { + x.set_DataPrePagamento((this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? x.get_Parcela().get_Emissao() : this.SelectedDocumento.get_Remessa())); + break; + } + default: + { + return; + } + } + } + }); + } + else + { + } + if (this.Repasses == null) + { + this.Repasses = new List() + { + this.PropriaCorretora() + }; + } + List vendedorParcelas = this.Repasses; + if (vendedorParcelas.All((VendedorParcela x) => x.get_TipoVendedor().get_Id() != (long)1)) + { + this.Repasses.Add(this.PropriaCorretora()); + } + Parcela parcela3 = await this.ParcelaServico.Save(this.SelectedParcela, this.Parcelas.ToList(), this.Repasses, true); + if (i == this.QuantidadeFaturas - 1) + { + this.SelectedParcela = parcela3; + } + } + this.QuantidadeFaturas = 0; + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = string.Concat("NA PROPOSTA \"", this.SelectedDocumento.get_Proposta(), "\""); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("NA PROPOSTA DE ENDOSSO \"", this.SelectedDocumento.get_PropostaEndosso(), "\"") : string.Concat("NO ENDOSSO \"", this.SelectedDocumento.get_Endosso(), "\"")); + } + else + { + str1 = string.Concat("NA APÓLICE \"", this.SelectedDocumento.get_Apolice(), "\""); + } + string str4 = str1; + str2 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 ? string.Concat("PARCELA ESPECIAL ADICIONADA, ", str4) : string.Concat("FATURA ", this.SelectedParcela.get_Fatura(), " ADICIONADA, ", str4)); + string str5 = str2; + base.RegistrarAcao(str5, this.SelectedParcela.get_Id(), new TipoTela?(5), this.GerarObs(this.SelectedDocumento)); + if (this.ParcelaServico.Sucesso) + { + BaseApoliceViewModel baseApoliceViewModel = this; + str3 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 ? "PARCELA ESPECIAL ADICIONADA COM SUCESSO" : "FATURA ADICIONADA COM SUCESSO"); + baseApoliceViewModel.ToggleSnackBar(str3, true); + } + await this.CarregarParcelas(this.SelectedDocumento); + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + BaseApoliceViewModel baseApoliceViewModel1 = this; + Parcela selectedParcela3 = this.SelectedParcela; + if (selectedParcela3 == null) + { + selectedParcela3 = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel1.SelecionaParcela(selectedParcela3); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + this.BaixarParcelas = false; + this.CriandoParcelaEspecial = false; + } + else + { + this.CriandoParcelaEspecial = false; + await base.ShowMessage("NÃO É POSSIVEL REPLICAR MAIS QUE 12 VEZES A MESMA FATURA. PROCESSO CANCELADO", "OK", "", false); + } + } + } + + public async Task>> AdicionarVendedor() + { + // + // Current member / type: System.Threading.Tasks.Task`1>> Gestor.Application.ViewModels.Generic.BaseApoliceViewModel::AdicionarVendedor() + // File path: C:\AggerSeguros\Gestor.Application.exe + // + // Product version: 0.0.0.0 + // Exception in: System.Threading.Tasks.Task>> AdicionarVendedor() + // + // Object reference not set to an instance of an object. + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.FindLowestCommonAncestor(ICollection`1 typeNodes) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 515 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.MergeWithLowestCommonAncestor() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 459 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.ProcessSingleConstraints() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 378 + // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.InferTypes() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 331 + // at Telerik.JustDecompiler.Decompiler.ExpressionDecompilerStep.Process(DecompilationContext theContext, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\ExpressionDecompilerStep.cs:line 104 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.Extensions.DecompileStateMachine(MethodBody body, DecompilationContext enclosingContext, BaseStateMachineRemoverStep removeStateMachineStep, Func`2 stateMachineDataSelector, DecompilationContext& decompilationContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 104 + // at Telerik.JustDecompiler.Decompiler.Extensions.DecompileAsyncStateMachine(MethodBody body, DecompilationContext enclosingContext, AsyncData& asyncData) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 150 + // at Telerik.JustDecompiler.Steps.RebuildAsyncStatementsStep.GetMoveNextStatements() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAsyncStatementsStep.cs:line 155 + // at Telerik.JustDecompiler.Steps.RebuildAsyncStatementsStep.Match() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAsyncStatementsStep.cs:line 60 + // at Telerik.JustDecompiler.Steps.RebuildAsyncStatementsStep.Process(DecompilationContext context, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAsyncStatementsStep.cs:line 31 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.Extensions.RunPipeline(DecompilationPipeline pipeline, ILanguage language, MethodBody body, DecompilationContext& context) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 95 + // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61 + // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 118 + // + // mailto: JustDecompilePublicFeedback@telerik.com + + } + + public async Task>> AdicionarVendedorParcelaEspecial() + { + List> keyValuePairs; + List list; + bool valueOrDefault; + bool flag; + bool flag1; + string str1; + DateTime? nullable; + DateTime dateTime; + DateTime? nullable1; + DateTime? nullable2; + bool flag2; + decimal num; + List vinculoRepasses; + List vendedorParcelas; + List> keyValuePairs1 = new List>(); + if (this.SelectedPagamento == null) + { + keyValuePairs1.Add(new KeyValuePair("SelectedPagamento|PAGAMENTO", "ERRO AO INCLUIR VENDEDOR.")); + keyValuePairs = keyValuePairs1; + } + else if (this.SelectedPagamento.get_Repasse() != null) + { + this.SelectedPagamento.set_Parcela(this.SelectedParcela); + if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 2 || this.SelectedPagamento.get_Repasse().get_Forma().GetValueOrDefault() != 3) + { + Gestor.Model.Domain.Seguros.Repasse repasse = this.SelectedPagamento.get_Repasse(); + if (repasse != null) + { + List vinculo = repasse.get_Vinculo(); + if (vinculo != null) + { + list = ( + from x in vinculo + where x.get_TipoVendedor().get_Id() == this.SelectedPagamento.get_TipoVendedor().get_Id() + select x).ToList(); + } + else + { + list = null; + } + } + else + { + list = null; + } + vinculoRepasses = list; + vendedorParcelas = new List() + { + this.SelectedPagamento + }; + if (this.SelectedDocumento.get_NegocioCorretora().HasValue) + { + NegocioCorretora? negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + valueOrDefault = negocioCorretora.GetValueOrDefault() == 1; + } + else if (this.SelectedDocumento.get_Situacao() != 2 || !this.SelectedDocumento.get_Negocio().HasValue) + { + valueOrDefault = false; + } + else + { + Negocio? negocio = this.SelectedDocumento.get_Negocio(); + valueOrDefault = negocio.GetValueOrDefault() == 1; + } + bool flag3 = valueOrDefault; + flag = (vinculoRepasses == null ? false : vinculoRepasses.Count > 0); + bool flag4 = flag; + if (flag4) + { + flag4 = await base.ShowMessage("DESEJA ADICIONAR OS REPASSES VINCULADOS?", "SIM", "NÃO", false); + } + if (flag4) + { + foreach (VinculoRepasse vinculoRepasse in vinculoRepasses) + { + Gestor.Model.Domain.Seguros.Repasse repasseVinculo = vinculoRepasse.get_RepasseVinculo(); + Parcela parcela = this.SelectedPagamento.get_Parcela(); + flag2 = (this.SelectedPagamento.get_Parcela() == null ? true : this.SelectedPagamento.get_Parcela().get_SubTipo() == 1); + decimal num1 = Funcoes.CalculaRepasse(repasseVinculo, parcela, flag2); + VendedorParcela vendedorParcela = new VendedorParcela(); + vendedorParcela.set_TipoVendedor(vinculoRepasse.get_TipoVendedorVinculo()); + vendedorParcela.set_Vendedor(vinculoRepasse.get_RepasseVinculo().get_Vendedor()); + vendedorParcela.set_Repasse(vinculoRepasse.get_RepasseVinculo()); + vendedorParcela.set_Documento(this.SelectedPagamento.get_Documento()); + vendedorParcela.set_Parcela(this.SelectedPagamento.get_Parcela()); + num = (flag3 ? vinculoRepasse.get_RepasseVinculo().get_ValorRenovacao() : vinculoRepasse.get_RepasseVinculo().get_ValorNovo()); + vendedorParcela.set_PorcentagemRepasse(new decimal?(num)); + vendedorParcela.set_ValorRepasse(new decimal?(num1)); + vendedorParcela.set_ValorTotal(new decimal?(num1)); + vendedorParcelas.Add(vendedorParcela); + } + } + foreach (VendedorParcela vendedorParcela1 in vendedorParcelas) + { + VendedorParcela vendedorParcela2 = vendedorParcela1; + keyValuePairs1 = vendedorParcela2.Validate(); + keyValuePairs1.AddRange(this.ValidateEspecial(vendedorParcela2)); + if (keyValuePairs1.Count <= 0) + { + if (vendedorParcela2.get_Repasse() != null) + { + BaseRepasse? @base = vendedorParcela2.get_Repasse().get_Base(); + if (@base.HasValue) + { + switch (@base.GetValueOrDefault()) + { + case 1: + { + VendedorParcela vendedorParcela3 = vendedorParcela2; + nullable = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? vendedorParcela2.get_Parcela().get_VigenciaIncial() : new DateTime?(this.SelectedDocumento.get_Vigencia1())); + vendedorParcela3.set_DataPrePagamento(nullable); + break; + } + case 2: + { + vendedorParcela2.set_DataPrePagamento(vendedorParcela2.get_Parcela().get_DataCriacao()); + break; + } + case 3: + { + VendedorParcela vendedorParcela4 = vendedorParcela2; + dateTime = (vendedorParcela2.get_Parcela().get_Vencimento() == DateTime.MinValue ? this.SelectedDocumento.get_Vigencia1() : vendedorParcela2.get_Parcela().get_Vencimento()); + vendedorParcela4.set_DataPrePagamento(new DateTime?(dateTime)); + break; + } + case 4: + { + VendedorParcela vendedorParcela5 = vendedorParcela2; + nullable1 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? vendedorParcela2.get_Parcela().get_Emissao() : this.SelectedDocumento.get_Emissao()); + vendedorParcela5.set_DataPrePagamento(nullable1); + break; + } + case 5: + { + VendedorParcela vendedorParcela6 = vendedorParcela2; + nullable2 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? vendedorParcela2.get_Parcela().get_Emissao() : this.SelectedDocumento.get_Remessa()); + vendedorParcela6.set_DataPrePagamento(nullable2); + break; + } + } + } + } + if (this.Pagamentos == null) + { + this.Pagamentos = new ObservableCollection(); + } + VendedorParcela vendedorParcela7 = this.Repasses.FirstOrDefault((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != this.SelectedParcela.get_Id() || x.get_TipoVendedor().get_Id() != (long)1) + { + return false; + } + return x.get_Vendedor().get_Corretora(); + }); + flag1 = (vendedorParcela2.get_TipoVendedor().get_Id() != (long)1 ? false : vendedorParcela7 != null); + bool flag5 = flag1; + if (this.SelectedParcela.get_Id() != 0) + { + if (vendedorParcela2.get_Repasse().get_Forma().GetValueOrDefault() == 1) + { + vendedorParcela2.set_DataPrePagamento(this.SelectedParcela.get_DataRecebimento()); + } + List vendedorParcelas1 = new List() + { + vendedorParcela2 + }; + vendedorParcelas1 = await this.Servico.IncluirVendedores(vendedorParcelas1); + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = string.Concat("NA PROPOSTA \"", this.SelectedDocumento.get_Proposta(), "\""); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("NA PROPOSTA DE ENDOSSO \"", this.SelectedDocumento.get_PropostaEndosso(), "\"") : string.Concat("NO ENDOSSO \"", this.SelectedDocumento.get_Endosso(), "\"")); + } + else + { + str1 = string.Concat("NA APÓLICE \"", this.SelectedDocumento.get_Apolice(), "\""); + } + string str2 = str1; + if (vendedorParcelas1 != null) + { + vendedorParcelas1.ForEach((VendedorParcela x) => { + string str = string.Concat("VENDEDOR ", x.get_Vendedor().get_Nome(), " ADICIONADO A PARCELA ESPECIAL, ", str2); + base.RegistrarAcao(str, x.get_Id(), new TipoTela?(37), string.Format("{0}{1}VENDEDOR: {2}{3}COMISSÃO TOTAL: {4:C2}", new object[] { this.GerarObs(this.SelectedDocumento), Environment.NewLine, x.get_Vendedor().get_Nome(), Environment.NewLine, x.get_ValorTotal() })); + }); + } + this.Repasses.AddRange(vendedorParcelas1); + if (flag5) + { + await this.ExcluirVendedor(vendedorParcela7, false); + } + this.Repasses = await this.VendedorServico.BuscaRepasse(this.SelectedDocumento.get_Id()); + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela == null) + { + selectedParcela = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel.SelecionaParcela(selectedParcela); + this.SelectedPagamento = null; + vendedorParcela7 = null; + } + else + { + this.Repasses.Add(vendedorParcela2); + this.Pagamentos.Add(vendedorParcela2); + this.SelectedPagamento = null; + if (!this.IsFatura && this.SelectedParcela.get_SubTipo() == 1 || !flag5) + { + continue; + } + await this.ExcluirVendedor(vendedorParcela7, false); + } + } + else + { + if (this.SelectedPagamento == null) + { + this.SelectedPagamento = vendedorParcela2; + } + keyValuePairs = keyValuePairs1; + vinculoRepasses = null; + vendedorParcelas = null; + return keyValuePairs; + } + } + base.ToggleSnackBar("VENDEDOR ADICIONADO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + base.ShowMessage("NÃO É POSSÍVEL ADICIONAR UM VENDEDOR COM A FORMA DE PAGAMENTO À PRAZO EM DOCUMENTOS DO TIPO FATURA", "OK", "", false); + keyValuePairs = null; + } + } + else + { + keyValuePairs1.Add(new KeyValuePair("Repasse|REPASSE", "ERRO AO INCLUIR VENDEDOR.")); + keyValuePairs = keyValuePairs1; + } + vinculoRepasses = null; + vendedorParcelas = null; + return keyValuePairs; + } + + public async void AjustaParcelasCoCorretagem() + { + int num = 0; + try + { + ObservableCollection parcelas = this.Parcelas; + foreach (Parcela parcela in parcelas) + { + if (parcela.get_NumeroParcela() != 999) + { + parcela.set_Comissao(this.SelectedDocumento.get_Comissao()); + } + else + { + return; + } + } + this.Parcelas = new ObservableCollection(await this.ParcelaServico.SaveRange(parcelas.ToList())); + await this.CarregarParcelas(this.SelectedDocumento); + } + catch + { + num = 1; + } + if (num == 1) + { + await base.ShowMessage("NÃO FOI POSSÍVEL SALVAR AS PARCELAS", "OK", "", false); + } + } + + public async Task AjusteComissãoCoCorretagem(bool removido = false) + { + decimal? nullable; + decimal valorNovo; + decimal? comissaoTotal; + int num = 0; + try + { + if (!removido) + { + VendedorParcela selectedPagamento = this.SelectedPagamento; + if (selectedPagamento != null) + { + valorNovo = selectedPagamento.get_Repasse().get_ValorNovo(); + } + else + { + valorNovo = decimal.Zero; + } + decimal num1 = valorNovo; + decimal comissao = this.SelectedDocumento.get_Comissao(); + this.SelectedDocumento.set_ComissaoTotal(new decimal?(comissao)); + this.SelectedDocumento.set_Comissao(Math.Round(comissao - (comissao * num1 * new decimal(1, 0, 0, false, 2)), 2)); + this.SelectedDocumento = await this.Servico.Save(this.SelectedDocumento, false, false); + this.AjustaParcelasCoCorretagem(); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + } + else + { + Documento selectedDocumento = this.SelectedDocumento; + Documento documento = this.SelectedDocumento; + if (documento != null) + { + comissaoTotal = documento.get_ComissaoTotal(); + } + else + { + nullable = null; + comissaoTotal = nullable; + } + nullable = comissaoTotal; + selectedDocumento.set_Comissao(nullable.GetValueOrDefault()); + this.SelectedDocumento = await this.Servico.Save(this.SelectedDocumento, false, false); + this.AjustaParcelasCoCorretagem(); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + return; + } + } + catch + { + num = 1; + } + if (num == 1) + { + await base.ShowMessage("NÃO FOI POSSÍVEL ALTERAR A COMISSÃO DA CO-CORRETAGEM", "OK", "", false); + } + } + + public async Task AlterarVencimento() + { + // + // Current member / type: System.Threading.Tasks.Task Gestor.Application.ViewModels.Generic.BaseApoliceViewModel::AlterarVencimento() + // File path: C:\AggerSeguros\Gestor.Application.exe + // + // Product version: 0.0.0.0 + // Exception in: System.Threading.Tasks.Task AlterarVencimento() + // + // An item with the same key has already been added. Key: Label0 + // at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) + // at System.Collections.Generic.Dictionary`2.System.Collections.Generic.ICollection>.Add(KeyValuePair`2 keyValuePair) + // at Telerik.JustDecompiler.Common.Extensions.AddRange[TKey,TValue](IDictionary`2 self, IDictionary`2 source) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Common\Extensions.cs:line 99 + // at Telerik.JustDecompiler.Steps.RebuildAnonymousDelegatesStep.AnonymousDelegateRebuilder.VisitObjectCreationExpression(ObjectCreationExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAnonymousDelegatesStep.cs:line 332 + // at Telerik.JustDecompiler.Ast.BaseCodeTransformer.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeTransformer.cs:line 273 + // at Telerik.JustDecompiler.Ast.BaseCodeTransformer.Visit[TCollection,TElement](TCollection original) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeTransformer.cs:line 312 + // at Telerik.JustDecompiler.Ast.BaseCodeTransformer.VisitMethodInvocationExpression(MethodInvocationExpression node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeTransformer.cs:line 500 + // at Telerik.JustDecompiler.Ast.BaseCodeTransformer.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeTransformer.cs:line 273 + // at Telerik.JustDecompiler.Ast.BaseCodeTransformer.VisitExpressionStatement(ExpressionStatement node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeTransformer.cs:line 384 + // at Telerik.JustDecompiler.Ast.BaseCodeTransformer.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeTransformer.cs:line 273 + // at Telerik.JustDecompiler.Steps.RebuildAnonymousDelegatesStep.AnonymousDelegateRebuilder.Match(BlockStatement theBlock, Int32 index) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAnonymousDelegatesStep.cs:line 74 + // at Telerik.JustDecompiler.Steps.RebuildAnonymousDelegatesStep.VisitBlockStatement(BlockStatement node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAnonymousDelegatesStep.cs:line 30 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.VisitIfStatement(IfStatement node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 409 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(IEnumerable collection) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 384 + // at Telerik.JustDecompiler.Steps.RebuildAnonymousDelegatesStep.VisitBlockStatement(BlockStatement node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAnonymousDelegatesStep.cs:line 33 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.VisitIfStatement(IfStatement node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 408 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(ICodeNode node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 351 + // at Telerik.JustDecompiler.Ast.BaseCodeVisitor.Visit(IEnumerable collection) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Ast\BaseCodeVisitor.cs:line 384 + // at Telerik.JustDecompiler.Steps.RebuildAnonymousDelegatesStep.VisitBlockStatement(BlockStatement node) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAnonymousDelegatesStep.cs:line 33 + // at Telerik.JustDecompiler.Steps.RebuildAnonymousDelegatesStep.Process(DecompilationContext context, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Steps\RebuildAnonymousDelegatesStep.cs:line 21 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100 + // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72 + // at Telerik.JustDecompiler.Decompiler.Extensions.RunPipeline(DecompilationPipeline pipeline, ILanguage language, MethodBody body, DecompilationContext& context) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 95 + // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61 + // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 118 + // + // mailto: JustDecompilePublicFeedback@telerik.com + + } + + private void AtualizaValores(bool renovacao) + { + this.Repasses.ForEach((VendedorParcela x) => { + decimal? nullable; + decimal? comissaoTotal; + if (x.get_Repasse() == null) + { + return; + } + if (x.get_Repasse().get_Tipo().GetValueOrDefault() == 1) + { + return; + } + Parcela parcela = x.get_Parcela(); + if (parcela.get_SubTipo() != 1) + { + return; + } + parcela.set_Documento(this.SelectedDocumento); + decimal numeroParcelas = Funcoes.CalculaRepasse(x.get_Repasse(), parcela, true); + decimal valorNovo = (renovacao ? x.get_Repasse().get_ValorRenovacao() : x.get_Repasse().get_ValorNovo()); + if (x.get_CoCorretagem()) + { + valorNovo = x.get_Repasse().get_ValorNovo(); + } + if (x.get_Repasse().get_Forma().GetValueOrDefault() == 3) + { + numeroParcelas /= this.SelectedDocumento.get_NumeroParcelas(); + } + if (x.get_CoCorretagem()) + { + decimal comissao = this.SelectedDocumento.get_Comissao(); + Documento selectedDocumento = this.SelectedDocumento; + if (selectedDocumento != null) + { + comissaoTotal = selectedDocumento.get_ComissaoTotal(); + } + else + { + nullable = null; + comissaoTotal = nullable; + } + nullable = comissaoTotal; + decimal valueOrDefault = nullable.GetValueOrDefault(); + numeroParcelas = this.SelectedDocumento.get_PremioLiquido() * ((valueOrDefault - comissao) / new decimal(100)); + } + x.set_PorcentagemRepasse(new decimal?(valorNovo)); + x.set_ValorRepasse(new decimal?(numeroParcelas)); + x.set_ValorTotal(new decimal?(numeroParcelas)); + }); + decimal num = (this.Parcelas.Count((Parcela x) => x.get_SubTipo() == 1) > 0 ? this.SelectedDocumento.get_PremioTotal() / this.Parcelas.Count((Parcela x) => x.get_SubTipo() == 1) : decimal.Zero); + ( + from x in this.Parcelas + where x.get_SubTipo() == 1 + select x).ToList().ForEach((Parcela x) => { + x.set_Valor(num); + x.set_Comissao(this.SelectedDocumento.get_Comissao()); + x.set_Vendedores(new ObservableCollection( + from r in this.Repasses + where r.get_Parcela().get_Id() == x.get_Id() + select r)); + }); + } + + internal async Task BaixarComissao() + { + decimal? nullable; + bool valueOrDefault; + decimal? tolerancia; + decimal num; + bool tipo; + bool flag; + string endosso; + string propostaEndosso; + string str; + bool valueOrDefault1; + string str1; + bool flag1; + long? nullable1; + if (this.SelectedParcela != null) + { + base.Loading(true); + if (!this.IsFatura) + { + valueOrDefault = false; + } + else + { + ObservableCollection parcelas = this.Parcelas; + IOrderedEnumerable numeroParcela = + from x in parcelas + orderby x.get_NumeroParcela() + select x; + Parcela parcela = numeroParcela.LastOrDefault((Parcela x) => x.get_SubTipo() == 1); + if (parcela != null) + { + nullable1 = new long?(parcela.get_Id()); + } + else + { + nullable1 = null; + } + long? nullable2 = nullable1; + long id = this.SelectedParcela.get_Id(); + valueOrDefault = nullable2.GetValueOrDefault() == id & nullable2.HasValue; + } + bool flag2 = valueOrDefault; + this.SelectedParcela.set_Documento(this.SelectedDocumento); + Parcela selectedParcela = this.SelectedParcela; + List list = this.Parcelas.ToList(); + List repasses = this.Repasses; + Documento selectedDocumento = this.SelectedDocumento; + if (selectedDocumento != null) + { + Controle controle = selectedDocumento.get_Controle(); + if (controle != null) + { + Seguradora seguradora = controle.get_Seguradora(); + if (seguradora != null) + { + tolerancia = seguradora.get_Tolerancia(); + } + else + { + nullable = null; + tolerancia = nullable; + } + } + else + { + nullable = null; + tolerancia = nullable; + } + } + else + { + nullable = null; + tolerancia = nullable; + } + decimal? nullable3 = tolerancia; + num = (nullable3.HasValue ? nullable3.GetValueOrDefault() : this.Tolerancia); + this.SelectedParcela = await Funcoes.BaixarComissao(selectedParcela, list, repasses, num, false); + Documento documento = this.SelectedDocumento; + if (documento != null) + { + tipo = documento.get_Tipo() == 0; + } + else + { + tipo = false; + } + if (!tipo || !string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + Documento selectedDocumento1 = this.SelectedDocumento; + if (selectedDocumento1 != null) + { + flag = selectedDocumento1.get_Tipo() == 0; + } + else + { + flag = false; + } + if (!flag || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + Documento documento1 = this.SelectedDocumento; + if (documento1 != null) + { + endosso = documento1.get_Endosso(); + } + else + { + endosso = null; + } + if (string.IsNullOrEmpty(endosso)) + { + Documento selectedDocumento2 = this.SelectedDocumento; + if (selectedDocumento2 != null) + { + propostaEndosso = selectedDocumento2.get_PropostaEndosso(); + } + else + { + propostaEndosso = null; + } + str = string.Concat("PROPOSTA DE ENDOSSO ", propostaEndosso); + } + else + { + str = string.Concat("ENDOSSO ", this.SelectedDocumento.get_Endosso()); + } + } + else + { + str = string.Concat("APÓLICE ", this.SelectedDocumento.get_Apolice()); + } + } + else + { + str = string.Concat("PROPOSTA ", this.SelectedDocumento.get_Proposta()); + } + string str2 = str; + Documento documento2 = this.SelectedDocumento; + if (documento2 != null) + { + valueOrDefault1 = documento2.get_TipoRecebimento().GetValueOrDefault() == 1; + } + else + { + valueOrDefault1 = false; + } + str1 = (valueOrDefault1 ? string.Format("PARCELA {0} BAIXADA, {1}", this.SelectedParcela.get_NumeroParcela(), str2) : string.Concat("FATURA ", this.SelectedParcela.get_Fatura(), " BAIXADA, ", str2)); + string str3 = str1; + base.RegistrarAcao(str3, this.SelectedParcela.get_Id(), new TipoTela?(5), this.GerarObs(this.SelectedDocumento)); + if (this.SelectedDocumento != null) + { + await this.CarregarParcelas(this.SelectedDocumento); + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + } + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela1 = this.SelectedParcela; + if (selectedParcela1 == null) + { + selectedParcela1 = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel.SelecionaParcela(selectedParcela1); + this.BaixarParcelas = false; + BaseApoliceViewModel baseApoliceViewModel1 = this; + ObservableCollection observableCollection = this.Parcelas; + IEnumerable subTipo = + from x in observableCollection + where x.get_SubTipo() == 1 + select x; + if (!subTipo.All((Parcela x) => !x.get_DataRecebimento().HasValue)) + { + flag1 = false; + } + else + { + List vendedorParcelas = this.Repasses; + IEnumerable subTipo1 = + from x in vendedorParcelas + where x.get_Parcela().get_SubTipo() == 1 + select x; + flag1 = subTipo1.All((VendedorParcela x) => !x.get_DataPagamento().HasValue); + } + baseApoliceViewModel1.AllowEditApolice = flag1; + base.Loading(false); + bool flag3 = flag2; + if (flag3) + { + flag3 = await base.ShowMessage("DESEJA INCLUIR A PRÓXIMA FATURA?", "SIM", "NÃO", false); + } + if (flag3) + { + this.UltimaFatura = true; + } + base.ToggleSnackBar("PARCELA BAIXADA COM SUCESSO", true); + } + } + + public async Task BuscarVendedores(bool verificarRamo = true) + { + List vendedors1; + List vendedores; + bool ramo; + bool id; + Func func = null; + if (this.RepassesVendedores == null) + { + this.RepassesVendedores = await this.VendedorServico.BuscaRepasses(); + BaseApoliceViewModel list = this; + List repassesVendedores = this.RepassesVendedores; + IEnumerable> groupings = + from x in repassesVendedores + group x by x.get_Vendedor().get_Id(); + IEnumerable vendedor = + from x in groupings + select x.First().get_Vendedor(); + list.TodosVendedores = ( + from x in vendedor + orderby x.get_Nome() + select x).ToList(); + } + Documento selectedDocumento = this.SelectedDocumento; + if (selectedDocumento != null) + { + vendedores = selectedDocumento.get_Vendedores(); + } + else + { + vendedores = null; + } + List vendedors2 = vendedores; + if (vendedors2 == null) + { + Documento documento = this.SelectedDocumento; + if (documento != null) + { + id = documento.get_Id() > (long)0; + } + else + { + id = false; + } + if (!id) + { + vendedors1 = new List(); + } + else + { + vendedors1 = await this.ParcelaServico.BuscarVendedores(this.SelectedDocumento.get_Id()); + } + vendedors2 = vendedors1; + } + List vendedors3 = vendedors2; + this.Vendedores = this.TodosVendedores.Where((Vendedor x) => { + if (x.get_IdEmpresa() != Recursos.Usuario.get_IdEmpresa()) + { + List vendedors = vendedors3; + Func u003cu003e9_1475 = BaseApoliceViewModel.u003cu003ec.u003cu003e9__147_5; + if (u003cu003e9_1475 == null) + { + u003cu003e9_1475 = (Vendedor y) => y.get_Id(); + BaseApoliceViewModel.u003cu003ec.u003cu003e9__147_5 = u003cu003e9_1475; + } + if (!vendedors.Select(u003cu003e9_1475).Contains(x.get_Id())) + { + return false; + } + } + if (x.get_Ativo()) + { + return !x.get_Corretora(); + } + return false; + }).ToList(); + List vendedorUsuarios = await base.VerificaVinculoVendedor(Recursos.Usuario); + if (vendedorUsuarios.Count > 0) + { + vendedorUsuarios.ForEach((VendedorUsuario x) => vendedors3.Add(x.get_Vendedor())); + this.Vendedores = vendedors3; + } + if (verificarRamo) + { + Documento selectedDocumento1 = this.SelectedDocumento; + if (selectedDocumento1 != null) + { + Controle controle = selectedDocumento1.get_Controle(); + if (controle != null) + { + ramo = controle.get_Ramo(); + } + else + { + ramo = false; + } + } + else + { + ramo = false; + } + if (ramo) + { + for (int i = this.Vendedores.Count - 1; i >= 0; i--) + { + List repasses = this.GetRepasses(this.Vendedores[i]); + List repasses1 = repasses; + if (!repasses1.Any((Gestor.Model.Domain.Seguros.Repasse x) => x.get_Ramo() == null)) + { + List repasses2 = repasses; + Func func1 = func; + if (func1 == null) + { + Func id1 = (Gestor.Model.Domain.Seguros.Repasse x) => x.get_Ramo().get_Id() != this.SelectedDocumento.get_Controle().get_Ramo().get_Id(); + Func func2 = id1; + func = id1; + func1 = func2; + } + if (repasses2.All(func1)) + { + this.Vendedores.Remove(this.Vendedores[i]); + } + } + } + } + } + } + + private void CalculaComissao(Documento documento, ObservableCollection parcelas) + { + decimal? nullable; + decimal? comissaoTotal; + decimal num = (documento.get_AdicionalComiss() ? documento.get_PremioLiquido() + documento.get_PremioAdicional() : documento.get_PremioLiquido()); + decimal comissao = documento.get_Comissao() * new decimal(1, 0, 0, false, 2); + this.Gerada = num * comissao; + this.Recebida = (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 32) ? parcelas.Where((Parcela x) => { + if (x.get_SubTipo() == 1) + { + return true; + } + return x.get_SubTipo() == 6; + }).Sum((Parcela x) => x.get_ValorComissao()) : ( + from x in parcelas + where x.get_SubTipo() == 1 + select x).Sum((Parcela x) => x.get_ValorComissao())); + this.Pendente = this.Gerada - this.Recebida; + this.Pendente = (this.Pendente < new decimal(1, 0, 0, false, 2) ? new decimal(0, 0, 0, false, 2) : this.Pendente); + this.Repasse = this.Repasses.Where((VendedorParcela x) => { + if (!x.get_DataPrePagamento().HasValue) + { + return false; + } + return !x.get_CoCorretagem(); + }).Sum((VendedorParcela x) => x.get_ValorRepasse().GetValueOrDefault()); + if (this.Pendente < this.Tolerancia) + { + this.Pendente = decimal.Zero; + } + if (this.VerificaCoCorretagem()) + { + Documento selectedDocumento = this.SelectedDocumento; + if (selectedDocumento != null) + { + comissaoTotal = selectedDocumento.get_ComissaoTotal(); + } + else + { + nullable = null; + comissaoTotal = nullable; + } + nullable = comissaoTotal; + this.ComissOriginal = nullable.GetValueOrDefault(); + } + } + + public VendedorParcela CalculaRepasse(Gestor.Model.Domain.Seguros.Repasse repasse, TipoVendedor tipoVendedor) + { + NegocioCorretora? negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + bool valueOrDefault = negocioCorretora.GetValueOrDefault() == 1; + if (this.SelectedParcela == null) + { + Parcela parcela = new Parcela(); + parcela.set_SubTipo(1); + parcela.set_IdEmpresa(this.SelectedDocumento.get_Controle().get_IdEmpresa()); + this.SelectedParcela = parcela; + } + this.SelectedParcela.set_Documento(this.SelectedDocumento); + decimal num = Funcoes.CalculaRepasse(repasse, this.SelectedParcela, true); + VendedorParcela vendedorParcela = new VendedorParcela(); + vendedorParcela.set_Repasse(repasse); + vendedorParcela.set_ValorRepasse(new decimal?(num)); + vendedorParcela.set_ValorTotal(new decimal?(num)); + vendedorParcela.set_Vendedor(repasse.get_Vendedor()); + vendedorParcela.set_PorcentagemRepasse(new decimal?((valueOrDefault ? repasse.get_ValorRenovacao() : repasse.get_ValorNovo()))); + vendedorParcela.set_TipoVendedor(tipoVendedor); + vendedorParcela.set_CoCorretagem((repasse != null ? repasse.get_Tipo().GetValueOrDefault() == 3 : false)); + return vendedorParcela; + } + + public async Task CancelarAlteracao() + { + this.Acesso = 0; + if (this.CancelDocumento == null || this.CancelDocumento.get_Id() == 0) + { + this.SelectedDocumento = null; + } + else + { + await this.SelecionaDocumento(this.CancelDocumento); + } + this.Anotacoes = string.Empty; + base.EnableFields = false; + Action enableMainMenu = Gestor.Application.Actions.Actions.EnableMainMenu; + if (enableMainMenu != null) + { + enableMainMenu(true); + } + else + { + } + Action enableMenu = Gestor.Application.Actions.Actions.EnableMenu; + if (enableMenu != null) + { + enableMenu(true); + } + else + { + } + Action enablePesquisarClientes = Gestor.Application.Actions.Actions.EnablePesquisarClientes; + if (enablePesquisarClientes != null) + { + enablePesquisarClientes(true); + } + else + { + } + } + + public async void CancelPagamento() + { + ObservableCollection observableCollection; + this.BaixarParcelas = false; + this.SelectedParcela.set_Baixando(false); + ObservableCollection observableCollection1 = await this.ParcelaServico.BuscarParcelasAsync(this.SelectedDocumento.get_Id()); + BaseApoliceViewModel baseApoliceViewModel = this; + if (this.IsFatura) + { + ObservableCollection observableCollection2 = observableCollection1; + observableCollection = new ObservableCollection( + from x in observableCollection2 + orderby x.get_NumeroParcela() descending + select x); + } + else + { + observableCollection = observableCollection1; + } + baseApoliceViewModel.Parcelas = observableCollection; + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + await this.SelecionaParcela(this.Parcelas.FirstOrDefault()); + } + + public async Task CarregaRepasse(long id) + { + this.Repasses = await this.VendedorServico.BuscaRepasse(id); + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela == null) + { + selectedParcela = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel.SelecionaParcela(selectedParcela); + } + + public async Task CarregarImposto() + { + List impostos = await (new ImpostoServico()).Buscar(new bool?(true)); + Gestor.Model.Domain.Ferramentas.Imposto imposto = impostos.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Imposto x) => { + if (x.get_Seguradora() == null || x.get_Seguradora().get_Id() != this.SelectedDocumento.get_Controle().get_Seguradora().get_Id() || x.get_Ramo() == null) + { + return false; + } + return x.get_Ramo().get_Id() == this.SelectedDocumento.get_Controle().get_Ramo().get_Id(); + }); + if (imposto == null) + { + imposto = impostos.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Imposto x) => { + if (x.get_Seguradora() == null || x.get_Seguradora().get_Id() != this.SelectedDocumento.get_Controle().get_Seguradora().get_Id()) + { + return false; + } + return x.get_Ramo() == null; + }); + } + if (imposto == null) + { + imposto = impostos.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Imposto x) => { + if (x.get_Seguradora() != null || x.get_Ramo() == null) + { + return false; + } + return x.get_Ramo().get_Id() == this.SelectedDocumento.get_Controle().get_Ramo().get_Id(); + }); + } + if (imposto == null) + { + List impostos1 = impostos; + imposto = impostos1.FirstOrDefault((Gestor.Model.Domain.Ferramentas.Imposto x) => { + if (x.get_Seguradora() != null) + { + return false; + } + return x.get_Ramo() == null; + }); + } + Gestor.Model.Domain.Ferramentas.Imposto imposto1 = imposto; + BaseApoliceViewModel baseApoliceViewModel = this; + Gestor.Model.Domain.Ferramentas.Imposto imposto2 = imposto1; + if (imposto2 == null) + { + imposto2 = new Gestor.Model.Domain.Ferramentas.Imposto(); + } + baseApoliceViewModel.Imposto = imposto2; + } + + public async Task CarregarParcelas(Documento documento) + { + ObservableCollection observableCollection; + if (documento != null) + { + ObservableCollection observableCollection1 = await this.ParcelaServico.BuscarParcelasPorDocumento(documento); + BaseApoliceViewModel baseApoliceViewModel = this; + if (this.IsFatura) + { + ObservableCollection observableCollection2 = observableCollection1; + observableCollection = new ObservableCollection( + from x in observableCollection2 + orderby x.get_NumeroParcela() descending + select x); + } + else + { + observableCollection = observableCollection1; + } + baseApoliceViewModel.Parcelas = observableCollection; + if (this.Invoke) + { + Action recarregarParcelas = Gestor.Application.Actions.Actions.RecarregarParcelas; + if (recarregarParcelas != null) + { + recarregarParcelas(this.SelectedDocumento); + } + else + { + } + } + } + } + + public bool CompararValores() + { + if (this.SelectedDocumento.get_Id() == 0 || this.SelectedDocumento.HasChange("PremioLiquido") || this.SelectedDocumento.HasChange("PremioAdicional") || this.SelectedDocumento.HasChange("Comissao") || this.SelectedDocumento.HasChange("Iof")) + { + return true; + } + return this.SelectedDocumento.HasChange("AdicionalComiss"); + } + + private void CriarParcelas(bool insert) + { + if (this.Repasses == null) + { + this.Repasses = new List(); + } + var list = this.Repasses.Where((VendedorParcela x) => { + if (insert) + { + return true; + } + return x.get_Parcela().get_SubTipo() == 1; + }).GroupBy((VendedorParcela x) => new { Repasse = x.get_Repasse(), TipoVendedor = x.get_TipoVendedor() }).Distinct().ToList(); + List vendedorParcelas = new List(); + list.ForEach((x) => { + decimal num; + if (x.Key.Repasse == null) + { + return; + } + VendedorParcela vendedorParcela = this.CalculaRepasse(x.Key.Repasse, x.Key.TipoVendedor); + if (vendedorParcela.get_Repasse().get_Forma().GetValueOrDefault() == 3) + { + VendedorParcela vendedorParcela1 = vendedorParcela; + decimal? valorRepasse = vendedorParcela1.get_ValorRepasse(); + num = (this.SelectedDocumento.get_NumeroParcelas() > decimal.Zero ? this.SelectedDocumento.get_NumeroParcelas() : decimal.One); + vendedorParcela1.set_ValorRepasse((valorRepasse.HasValue ? new decimal?(valorRepasse.GetValueOrDefault() / num) : null)); + } + vendedorParcelas.Add(vendedorParcela); + }); + if (vendedorParcelas.All((VendedorParcela x) => x.get_TipoVendedor().get_Id() != (long)1)) + { + vendedorParcelas.Add(this.PropriaCorretora()); + } + this.Parcelas = new ObservableCollection(this.CriarParcelas(vendedorParcelas)); + } + + private List CriarParcelas(List vendedores) + { + TipoPagamento tipoPagamento; + List parcelas = new List(); + if (this.SelectedDocumento.get_NumeroParcelas() == decimal.Zero) + { + return parcelas; + } + decimal premioTotal = this.SelectedDocumento.get_PremioTotal() / this.SelectedDocumento.get_NumeroParcelas(); + FormaPagamento? formaPagamento = this.SelectedDocumento.get_FormaPagamento(); + if (!formaPagamento.HasValue) + { + this.SelectedDocumento.set_FormaPagamento(new FormaPagamento?(0)); + } + for (int i = 1; i <= this.SelectedDocumento.get_NumeroParcelas(); i++) + { + Parcela parcela = new Parcela(); + parcela.set_IdEmpresa(this.SelectedDocumento.get_Controle().get_IdEmpresa()); + parcela.set_NumeroParcela(i); + parcela.set_Valor(premioTotal); + parcela.set_Comissao(this.SelectedDocumento.get_Comissao()); + DateTime vigencia1 = this.SelectedDocumento.get_Vigencia1(); + parcela.set_Vencimento(vigencia1.AddMonths(i - 1)); + parcela.set_SubTipo(1); + parcela.set_Vendedores(new ObservableCollection((i == 1 ? vendedores : vendedores.Where((VendedorParcela x) => { + Gestor.Model.Domain.Seguros.Repasse repasse = x.get_Repasse(); + if (repasse == null) + { + return false; + } + return repasse.get_Forma().GetValueOrDefault() == 3; + }).ToList()))); + formaPagamento = this.SelectedDocumento.get_FormaPagamento(); + if (formaPagamento.GetValueOrDefault() == 0 & formaPagamento.HasValue) + { + tipoPagamento = 7; + } + else + { + formaPagamento = this.SelectedDocumento.get_FormaPagamento(); + if (formaPagamento.GetValueOrDefault() == 1) + { + tipoPagamento = 3; + } + else + { + formaPagamento = this.SelectedDocumento.get_FormaPagamento(); + if (formaPagamento.GetValueOrDefault() == 2) + { + tipoPagamento = 15; + } + else + { + formaPagamento = this.SelectedDocumento.get_FormaPagamento(); + tipoPagamento = (formaPagamento.GetValueOrDefault() != 3 || i != 1 ? 7 : 15); + } + } + } + parcela.set_TipoPagamento(tipoPagamento); + parcela.set_DataCriacao(new DateTime?(Funcoes.GetNetworkTime())); + parcela.set_UsuarioCriacao(Recursos.Usuario.get_Id()); + parcelas.Add(parcela); + } + return parcelas; + } + + private List CriarRepasses(VendedorParcela repasse) + { + decimal? nullable; + if (this.Parcelas == null || this.Parcelas.Count == 0 || this.SelectedDocumento == null) + { + return null; + } + List vendedorParcelas = new List(); + VendedorParcela vendedorParcela1 = repasse; + if (repasse.get_Repasse().get_Forma().GetValueOrDefault() == 3) + { + decimal? valorRepasse = repasse.get_ValorRepasse(); + decimal numeroParcelas = this.SelectedDocumento.get_NumeroParcelas(); + if (valorRepasse.HasValue) + { + nullable = new decimal?(valorRepasse.GetValueOrDefault() / numeroParcelas); + } + else + { + nullable = null; + } + } + else + { + nullable = repasse.get_ValorRepasse(); + } + vendedorParcela1.set_ValorRepasse(nullable); + this.Parcelas.ToList().ForEach((Parcela x) => { + if (repasse.get_Repasse().get_Forma().GetValueOrDefault() != 3 && x.get_NumeroParcela() > 1) + { + return; + } + VendedorParcela vendedorParcela = (VendedorParcela)repasse.Clone(); + if (repasse.get_Repasse().get_Forma().GetValueOrDefault() == 3) + { + vendedorParcela.set_DataPrePagamento(new DateTime?(x.get_Vencimento())); + } + vendedorParcela.set_Parcela(x); + vendedorParcelas.Add(vendedorParcela); + }); + return vendedorParcelas; + } + + private async Task DesfazerAlteracoes() + { + IEnumerable list; + ItemServico itemServico = new ItemServico(); + IList documentos = this.SelectedDocumento.get_Controle().get_Documentos(); + ObservableCollection observableCollection = await itemServico.BuscarItems(documentos.FirstOrDefault((Documento x) => { + if (x.get_Excluido() || x.get_Situacao() == 7) + { + return false; + } + return x.get_Ordem() == 0; + }).get_Id(), 2, false); + ObservableCollection observableCollection1 = await (new ItemServico()).BuscarItems(this.SelectedDocumento.get_Id(), 2, false); + ObservableCollection observableCollection2 = observableCollection1; + List items = observableCollection.Where((Item x) => { + long? idDocumentoCancelado = x.get_IdDocumentoCancelado(); + long id = this.SelectedDocumento.get_Id(); + return idDocumentoCancelado.GetValueOrDefault() == id & idDocumentoCancelado.HasValue; + }).ToList(); + List items1 = items; + IEnumerable items2 = observableCollection.Where((Item x) => { + long? nullable; + long? nullable1 = x.get_Substituido(); + if (!nullable1.HasValue) + { + return false; + } + nullable1 = x.get_Substituido(); + Item item = observableCollection2.FirstOrDefault((Item d) => { + long id = d.get_Id(); + long? substituido = x.get_Substituido(); + return id == substituido.GetValueOrDefault() & substituido.HasValue; + }); + if (item != null) + { + nullable = new long?(item.get_Id()); + } + else + { + nullable = null; + } + long? nullable2 = nullable; + return nullable1.GetValueOrDefault() == nullable2.GetValueOrDefault() & nullable1.HasValue == nullable2.HasValue; + }); + if (items2 != null) + { + list = items2.ToList(); + } + else + { + list = null; + } + items1.AddRange(list); + if (items.Count == 0) + { + items = observableCollection.Where((Item x) => { + if (x.get_Status() == null || Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(x.get_Status()) || !x.get_Status().Contains("ORDEM")) + { + return false; + } + return x.get_Status().Replace("ORDEM", "-").Split(new char[] { '-' })[1].Trim().Equals(string.Format("{0}", this.SelectedDocumento.get_Ordem())); + }).ToList(); + } + foreach (Item item1 in items) + { + await (new ItemServico()).Reativar(item1, ""); + } + observableCollection = null; + } + + public void EditarParcelaEspecial() + { + this.AllowEditVendedor = true; + } + + public async Task EditarParcelas() + { + if (this.DocumentoSelecionado == null) + { + this.DocumentoSelecionado = this.SelectedDocumento; + } + await base.ShowEditarParcelasDialog(this.DocumentoSelecionado); + await this.CarregarParcelas(this.DocumentoSelecionado); + } + + public async Task ExcluirApolice() + { + string str; + int ordem; + string str1; + string str2; + TipoSeguro value; + int? nullable; + Documento selectedDocumento; + string str3; + string str4; + if (this.SelectedDocumento != null) + { + if (this.AllowEditApolice) + { + ObservableCollection parcelas = this.Parcelas; + if (!parcelas.Any((Parcela x) => x.get_DataRecebimento().HasValue)) + { + List repasses = this.Repasses; + if (!repasses.Any((VendedorParcela x) => x.get_DataPagamento().HasValue)) + { + if (this.SelectedDocumento.get_Tipo() <= 0 || !this.SelectedDocumento.get_Sinistro()) + { + selectedDocumento = this.SelectedDocumento; + if (selectedDocumento.get_Tipo() != 0 || !string.IsNullOrEmpty(selectedDocumento.get_Apolice())) + { + str = (selectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(selectedDocumento.get_Apolice()) ? "O ENDOSSO SELECIONADO" : "A APÓLICE SELECIONADA"); + } + else + { + str = "A PROPOSTA SELECIONADA"; + } + str3 = str; + int num = this.SelectedDocumento.get_Ordem(); + IList documentos = this.SelectedDocumento.get_Controle().get_Documentos(); + Documento documento = ( + from x in documentos + orderby x.get_Ordem() descending + select x).FirstOrDefault((Documento x) => { + if (!x.get_Excluido() && x.get_Situacao() != 7) + { + return true; + } + return x.get_Id() == this.SelectedDocumento.get_Id(); + }); + if (documento != null) + { + ordem = documento.get_Ordem(); + } + else + { + ordem = this.SelectedDocumento.get_Ordem(); + } + if (num == ordem) + { + string[] newLine = new string[] { "DESEJA REALMENTE EXCLUIR ", str3, "?", Environment.NewLine, "ESSE PROCEDIMENTO É IRREVERSÍVEL." }; + if (await base.ShowMessage(string.Concat(newLine), "SIM", "NÃO", false)) + { + bool hasValue = selectedDocumento.get_TipoEndosso().HasValue; + if (hasValue) + { + hasValue = await base.ShowMessage("DESEJA DESFAZER AS ALTERAÇOES NOS ITENS VINCULADOS A ESSE ENDOSSO ?", "SIM", "NÃO", false); + } + if (hasValue) + { + IList documentos1 = this.SelectedDocumento.get_Controle().get_Documentos(); + Documento documento1 = ( + from x in documentos1 + orderby x.get_Ordem() descending + select x).FirstOrDefault((Documento x) => { + if (x.get_Excluido() || x.get_Situacao() == 7) + { + return false; + } + return x.get_Ordem() > this.SelectedDocumento.get_Ordem(); + }); + if (documento1 != null) + { + nullable = new int?(documento1.get_Ordem()); + } + else + { + nullable = null; + } + int? nullable1 = nullable; + int ordem1 = this.SelectedDocumento.get_Ordem(); + if (!(nullable1.GetValueOrDefault() > ordem1 & nullable1.HasValue)) + { + await this.DesfazerAlteracoes(); + } + else + { + await base.ShowMessage(string.Concat("NÃO É POSSIVEL DESFAZER AS ALTERAÇÕES, POIS ", str3, " POSSUE ENDOSSOS ATIVOS ACIMA."), "OK", "", false); + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + if (selectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(selectedDocumento.get_Apolice())) + { + str1 = string.Concat("EXCLUIU PROPOSTA ", selectedDocumento.get_Proposta()); + } + else if (selectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(selectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(selectedDocumento.get_Endosso()) ? string.Concat("EXCLUIU PROPOSTA DE ENDOSSO ", selectedDocumento.get_PropostaEndosso()) : string.Concat("EXCLUIU ENDOSSO ", selectedDocumento.get_Endosso())); + } + else + { + str1 = string.Concat("EXCLUIU APÓLICE ", selectedDocumento.get_Apolice()); + } + string str5 = str1; + base.RegistrarAcao(str5, this.SelectedDocumento.get_Id(), new TipoTela?(2), this.GerarObs(selectedDocumento)); + base.Loading(true); + if (selectedDocumento.get_Tipo() != 0 || !string.IsNullOrEmpty(selectedDocumento.get_Apolice())) + { + str2 = (selectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(selectedDocumento.get_Apolice()) ? "ENDOSSO EXCLUÍDO" : "APÓLICE EXCLUÍDA"); + } + else + { + str2 = "PROPOSTA EXCLUÍDA"; + } + str4 = str2; + selectedDocumento.set_Excluido(true); + this.Servico.Sucesso = true; + await this.Servico.ExcluirCritica(selectedDocumento.get_Id()); + if (this.Servico.Sucesso) + { + Gestor.Application.Servicos.TarefaServico tarefaServico = this.TarefaServico; + hasValue = await this.TarefaServico.ExcluirTarefasDocumento(selectedDocumento.get_Id()); + tarefaServico.Sucesso = hasValue; + tarefaServico = null; + if (this.TarefaServico.Sucesso) + { + this.Servico.Sucesso = true; + if (selectedDocumento.get_TipoEndosso().HasValue && selectedDocumento.get_TipoEndosso().GetValueOrDefault() == 2) + { + IList documentos2 = this.CancelDocumento.get_Controle().get_Documentos(); + Documento documento2 = documentos2.FirstOrDefault((Documento x) => { + if (x.get_Tipo() != 0) + { + return false; + } + return !x.get_Excluido(); + }); + IList documentos3 = this.CancelDocumento.get_Controle().get_Documentos(); + List list = documentos3.Where((Documento x) => { + if (x.get_Tipo() != 1) + { + return false; + } + return !x.get_Excluido(); + }).ToList(); + if (documento2 != null) + { + Documento documento3 = documento2; + if (!documento2.get_SituacaoAnterior().HasValue || documento2.get_SituacaoAnterior().GetValueOrDefault() == 3) + { + value = (documento2.get_NegocioCorretora().GetValueOrDefault() == 1 ? 2 : 1); + } + else + { + value = documento2.get_SituacaoAnterior().Value; + } + documento3.set_Situacao(value); + await this.Servico.Save(documento2, false, false); + foreach (Documento documento4 in list) + { + documento4.set_Situacao(documento2.get_Situacao()); + await this.Servico.Save(documento4, false, false); + } + } + documento2 = null; + list = null; + } + await this.Servico.Excluir(selectedDocumento); + if (this.Servico.Sucesso) + { + if (selectedDocumento.get_Tipo() > 0) + { + await Funcoes.OrganizarDocumentos(selectedDocumento.get_Controle().get_Id()); + await Funcoes.InativarItens(selectedDocumento.get_Id(), selectedDocumento.get_Controle().get_Ramo().get_Id(), true); + } + if (this.Invoke) + { + ConsultaViewModel.DocumentoSelecionado = null; + Action recarregarDocumentos = Gestor.Application.Actions.Actions.RecarregarDocumentos; + if (recarregarDocumentos != null) + { + recarregarDocumentos(null); + } + else + { + } + } + base.Loading(false); + base.ToggleSnackBar(string.Concat(str4, " COM SUCESSO"), true); + if (this.Invoke) + { + Action acessaTela = Gestor.Application.Actions.Actions.AcessaTela; + if (acessaTela != null) + { + acessaTela(21, ""); + } + else + { + } + } + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + else + { + base.Loading(false); + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + else + { + base.Loading(false); + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + else + { + base.Loading(false); + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + else + { + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + else + { + await base.ShowMessage(string.Concat(str3, " NÃO PODE SER EXCLUÍDO(A) POIS POSSUEM DOCUMENTOS ATIVOS ACIMA."), "OK", "", false); + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + else + { + await base.ShowMessage("DOCUMENTO NÃO PODE SER EXCLUÍDO POIS POSSUI SINISTROS PARA UM OU MAIS DE SEUS ITENS.", "OK", "", false); + selectedDocumento = null; + str3 = null; + str4 = null; + return; + } + } + } + } + await base.ShowMessage("DOCUMENTO NÃO PODE SER EXCLUÍDO POIS POSSUI BAIXAS DE COMISSÃO OU PAGAMENTO DE VENDEDORES.", "OK", "", false); + } + selectedDocumento = null; + str3 = null; + str4 = null; + } + + internal async Task ExcluirBaixa() + { + string str; + string str1; + bool flag; + if (this.SelectedParcela != null) + { + if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR A BAIXA DA PARCELA SELECIONADA?", Environment.NewLine, "ESSE PROCEDIMENTO É IRREVERSÍVEL."), "SIM", "NÃO", false)) + { + base.Loading(true); + this.SelectedParcela.set_Documento(this.SelectedDocumento); + this.SelectedParcela = await Funcoes.ExcluirBaixa(this.SelectedParcela, this.Repasses, this.Parcelas.ToList()); + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str = string.Concat("PROPOSTA ", this.SelectedDocumento.get_Proposta()); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("PROPOSTA DE ENDOSSO ", this.SelectedDocumento.get_PropostaEndosso()) : string.Concat("ENDOSSO ", this.SelectedDocumento.get_Endosso())); + } + else + { + str = string.Concat("APÓLICE ", this.SelectedDocumento.get_Apolice()); + } + string str2 = str; + str1 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 ? string.Format("BAIXA DA PARCELA {0} EXCLUÍDA, {1}", this.SelectedParcela.get_NumeroParcela(), str2) : string.Concat("BAIXA DA FATURA ", this.SelectedParcela.get_Fatura(), " EXCLUÍDA, ", str2)); + string str3 = str1; + base.RegistrarAcao(str3, this.SelectedParcela.get_Id(), new TipoTela?(5), this.GerarObs(this.SelectedDocumento)); + await this.CarregarParcelas(this.SelectedDocumento); + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela == null) + { + selectedParcela = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel.SelecionaParcela(selectedParcela); + this.BaixarParcelas = false; + BaseApoliceViewModel baseApoliceViewModel1 = this; + ObservableCollection parcelas = this.Parcelas; + IEnumerable subTipo = + from x in parcelas + where x.get_SubTipo() == 1 + select x; + if (!subTipo.All((Parcela x) => !x.get_DataRecebimento().HasValue)) + { + flag = false; + } + else + { + List repasses = this.Repasses; + IEnumerable vendedorParcelas = + from x in repasses + where x.get_Parcela().get_SubTipo() == 1 + select x; + flag = vendedorParcelas.All((VendedorParcela x) => !x.get_DataPagamento().HasValue); + } + baseApoliceViewModel1.AllowEditApolice = flag; + base.Loading(false); + base.ToggleSnackBar("BAIXA EXCLUÍDA COM SUCESSO", true); + } + } + } + + public async Task ExcluirPagamento(VendedorParcela pagamento) + { + bool flag; + string str; + base.Loading(true); + if (await Funcoes.ExcluirPagamento(pagamento)) + { + base.ToggleSnackBar("PAGAMENTO EXCLUÍDO COM SUCESSO", true); + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str = string.Concat("NA PROPOSTA \"", this.SelectedDocumento.get_Proposta(), "\""); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("NA PROPOSTA DE ENDOSSO \"", this.SelectedDocumento.get_PropostaEndosso(), "\"") : string.Concat("NO ENDOSSO \"", this.SelectedDocumento.get_Endosso(), "\"")); + } + else + { + str = string.Concat("NA APÓLICE \"", this.SelectedDocumento.get_Apolice(), "\""); + } + string str1 = str; + string str2 = string.Concat("PAGAMENTO DO VENDEDOR ", pagamento.get_Vendedor().get_Nome(), " EXCLUÍDO, ", str1); + long id = pagamento.get_Id(); + TipoTela? nullable = new TipoTela?(37); + object[] objArray = new object[] { this.GerarObs(this.SelectedDocumento), Environment.NewLine, pagamento.get_Vendedor().get_Nome(), Environment.NewLine, pagamento.get_ValorTotal() }; + base.RegistrarAcao(str2, id, nullable, string.Format("{0}{1}VENDEDOR: {2}{3}COMISSÃO TOTAL: {4:C2}", objArray)); + } + await this.CarregarParcelas(this.SelectedDocumento); + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + await this.SelecionaParcela(this.Parcelas.FirstOrDefault()); + BaseApoliceViewModel baseApoliceViewModel = this; + ObservableCollection parcelas = this.Parcelas; + IEnumerable subTipo = + from x in parcelas + where x.get_SubTipo() == 1 + select x; + if (!subTipo.All((Parcela x) => !x.get_DataRecebimento().HasValue)) + { + flag = false; + } + else + { + List repasses = this.Repasses; + IEnumerable vendedorParcelas = + from x in repasses + where x.get_Parcela().get_SubTipo() == 1 + select x; + flag = vendedorParcelas.All((VendedorParcela x) => !x.get_DataPagamento().HasValue); + } + baseApoliceViewModel.AllowEditApolice = flag; + this.BaixarParcelas = false; + base.Loading(false); + } + + public async Task ExcluirParcela() + { + string str; + string str1; + string str2; + if (this.SelectedParcela != null) + { + if (this.SelectedParcela.get_SubTipo() != 1 || this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 1) + { + if (this.SelectedParcela.get_SubTipo() == 1) + { + ObservableCollection parcelas = this.Parcelas; + IOrderedEnumerable numeroParcela = + from x in parcelas + orderby x.get_NumeroParcela() + select x; + Parcela parcela = numeroParcela.Last((Parcela x) => x.get_SubTipo() == 1); + if (this.SelectedParcela.get_Id() != parcela.get_Id()) + { + await base.ShowMessage("A FATURA NÃO PODE SER EXCLUÍDA POIS HÁ FATURAS CADASTRADAS ACIMA DA SELECIONADA.", "OK", "", false); + return; + } + } + if (await base.ShowMessage(string.Concat("DESEJA REALMENTE EXCLUIR A PARCELA SELECIONADA?", Environment.NewLine, "ESSE PROCEDIMENTO É IRREVERSÍVEL."), "SIM", "NÃO", false)) + { + base.Loading(true); + if (await this.ParcelaServico.Delete(this.SelectedParcela, this.Parcelas.ToList())) + { + BaseApoliceViewModel baseApoliceViewModel = this; + str = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 ? "PARCELA EXCLUÍDA COM SUCESSO" : "FATURA EXCLUÍDA COM SUCESSO"); + baseApoliceViewModel.ToggleSnackBar(str, true); + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = string.Concat("PROPOSTA ", this.SelectedDocumento.get_Proposta()); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("PROPOSTA DE ENDOSSO ", this.SelectedDocumento.get_PropostaEndosso()) : string.Concat("ENDOSSO ", this.SelectedDocumento.get_Endosso())); + } + else + { + str1 = string.Concat("APÓLICE ", this.SelectedDocumento.get_Apolice()); + } + string str3 = str1; + str2 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 ? string.Format("PARCELA {0} EXCLUÍDA, {1}", this.SelectedParcela.get_NumeroParcela(), str3) : string.Concat("FATURA ", this.SelectedParcela.get_Fatura(), " EXCLUÍDA, ", str3)); + string str4 = str2; + base.RegistrarAcao(str4, this.SelectedParcela.get_Id(), new TipoTela?(5), this.GerarObs(this.SelectedDocumento)); + } + await this.CarregarParcelas(this.SelectedDocumento); + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + await this.SelecionaParcela(this.Parcelas.FirstOrDefault()); + this.BaixarParcelas = false; + if (this.Parcelas == null || this.Parcelas.Count == 0) + { + this.VisibilityExcluirParcela = Visibility.Collapsed; + this.VisibilityReplicarFatura = Visibility.Collapsed; + this.BaixarParcelaVisibility = Visibility.Collapsed; + } + base.Loading(false); + this.AllowEditVendedor = this.Parcelas.Any(); + } + } + } + } + + public async Task ExcluirVendedor(VendedorParcela pagamento, bool incluirCorretora = true) + { + List vendedorParcelas; + bool flag; + Vendedor vendedor; + string str1; + List list; + if (this.IsEndosso && this.SelectedDocumento.get_Id() == 0) + { + this.RemoverVendedor(pagamento.get_Vendedor().get_Id()); + base.ToggleSnackBar("VENDEDOR EXCLUÍDO COM SUCESSO", true); + } + else if (!this.AllowEditApolice && !this.IsFatura && this.SelectedParcela.get_SubTipo() == 1) + { + string[] upper = new string[] { "O VENDEDOR ", pagamento.get_Vendedor().get_Nome().ToUpper(), " NÃO PODE SER EXCLUÍDO.", Environment.NewLine, "JÁ EXISTEM RECEBIMENTOS OU PAGAMENTOS DE COMISSÃO PARA ESSE DOCUMENTO." }; + await base.ShowMessage(string.Concat(upper), "OK", "", false); + } + else if (this.SelectedDocumento.get_Id() > (long)0 && (this.IsFatura || this.SelectedParcela.get_SubTipo() != 1) && (this.SelectedParcela.get_Id() > (long)0 && this.SelectedParcela.get_DataRecebimento().HasValue || this.Repasses.Any((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != this.SelectedParcela.get_Id()) + { + return false; + } + return x.get_DataPagamento().HasValue; + }))) + { + string[] strArrays = new string[] { "O VENDEDOR ", pagamento.get_Vendedor().get_Nome().ToUpper(), " NÃO PODE SER EXCLUÍDO.", Environment.NewLine, "JÁ EXISTEM RECEBIMENTOS OU PAGAMENTOS DE COMISSÃO PARA ESSA FATURA." }; + await base.ShowMessage(string.Concat(strArrays), "OK", "", false); + } + else if (this.SelectedDocumento.get_Id() != 0) + { + vendedorParcelas = (this.SelectedParcela.get_SubTipo() != 1 || this.IsFatura ? this.Repasses.Where((VendedorParcela x) => { + if (x.get_Vendedor().get_Id() != pagamento.get_Vendedor().get_Id()) + { + return false; + } + return x.get_Parcela().get_Id() == this.SelectedParcela.get_Id(); + }).ToList() : this.Repasses.Where((VendedorParcela x) => { + if (x.get_Vendedor().get_Id() != pagamento.get_Vendedor().get_Id()) + { + return false; + } + return x.get_Parcela().get_NumeroParcela() != 999; + }).ToList()); + list = vendedorParcelas.Distinct().ToList(); + if (await this.Servico.ExcluirPagamento(list)) + { + if (this.SelectedParcela.get_Id() > (long)0) + { + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = string.Concat("NA PROPOSTA \"", this.SelectedDocumento.get_Proposta(), "\""); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("NA PROPOSTA DE ENDOSSO \"", this.SelectedDocumento.get_PropostaEndosso(), "\"") : string.Concat("NO ENDOSSO \"", this.SelectedDocumento.get_Endosso(), "\"")); + } + else + { + str1 = string.Concat("NA APÓLICE \"", this.SelectedDocumento.get_Apolice(), "\""); + } + string str2 = str1; + list.ForEach((VendedorParcela x) => { + string str = string.Concat("VENDEDOR ", x.get_Vendedor().get_Nome(), " EXCLUÍDO, ", str2); + base.RegistrarAcao(str, x.get_Id(), new TipoTela?(37), string.Format("{0}{1}VENDEDOR: {2}{3}COMISSÃO TOTAL: {4:C2}", new object[] { this.GerarObs(this.SelectedDocumento), Environment.NewLine, x.get_Vendedor().get_Nome(), Environment.NewLine, x.get_ValorTotal() })); + }); + } + this.RemoverVendedor(pagamento.get_Vendedor().get_Id()); + if (this.IsFatura || this.SelectedParcela.get_SubTipo() != 1) + { + flag = this.Repasses.Any((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != this.SelectedParcela.get_Id()) + { + return false; + } + return x.get_TipoVendedor().get_Id() == (long)1; + }); + } + else + { + List repasses = this.Repasses; + flag = repasses.Any((VendedorParcela x) => { + if (x.get_Parcela().get_SubTipo() != 1 || x.get_TipoVendedor().get_Id() != (long)1) + { + return false; + } + return !x.get_CoCorretagem(); + }); + } + bool flag1 = flag; + if (pagamento.get_TipoVendedor().get_Id() == (long)1 & incluirCorretora && !flag1) + { + VendedorParcela vendedorParcela = await this.IncluirPropriaCorretora(); + if (vendedorParcela != null) + { + this.Repasses.Add(vendedorParcela); + Documento selectedDocumento = this.SelectedDocumento; + List repasses1 = this.Repasses; + VendedorParcela vendedorParcela1 = repasses1.FirstOrDefault((VendedorParcela x) => x.get_TipoVendedor().get_Id() == (long)1); + if (vendedorParcela1 != null) + { + vendedor = vendedorParcela1.get_Vendedor(); + } + else + { + vendedor = null; + } + selectedDocumento.set_VendedorPrincipal(vendedor); + } + } + if (this.Repasses != null) + { + this.Pagamentos = new ObservableCollection(( + from x in this.Repasses + where x.get_Parcela().get_Id() == this.SelectedParcela.get_Id() + select x).ToList()); + } + base.ToggleSnackBar("VENDEDOR EXCLUÍDO COM SUCESSO", true); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + } + else + { + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela == null) + { + selectedParcela = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel.SelecionaParcela(selectedParcela); + } + } + else + { + this.RemoverVendedor(pagamento.get_Vendedor().get_Id()); + base.ToggleSnackBar("VENDEDOR EXCLUÍDO COM SUCESSO", true); + } + list = null; + } + + public void FiltrarRepasse(Vendedor vendedor) + { + if (this.SelectedPagamento == null) + { + this.SelectedPagamento = new VendedorParcela(); + } + this.SelectedPagamento.set_Vendedor(vendedor); + this.RepassesVendedor = this.GetRepasses(vendedor); + } + + public string GerarObs(Documento doc) + { + if (doc.get_Tipo() == 0) + { + return string.Format("CLIENTE: {0}{1}CÓDIGO: {2}{3}PROPOSTA: {4}{5}APÓLICE: {6}", new object[] { doc.get_Controle().get_Cliente().get_Nome(), Environment.NewLine, doc.get_Id(), Environment.NewLine, doc.get_Proposta(), Environment.NewLine, doc.get_Apolice() }); + } + return string.Format("CLIENTE: {0}{1}CÓDIGO: {2}{3}PROPOSTA: {4}{5}APÓLICE: {6}{7}PROPOSTA DE ENDOSSO: {8}{9}ENDOSSO: {10}", new object[] { doc.get_Controle().get_Cliente().get_Nome(), Environment.NewLine, doc.get_Id(), Environment.NewLine, doc.get_Proposta(), Environment.NewLine, doc.get_Apolice(), Environment.NewLine, doc.get_PropostaEndosso(), Environment.NewLine, doc.get_Endosso() }); + } + + public List GetRepasses(Vendedor vendedor) + { + List repasses; + if (this.CoCorretagem) + { + IEnumerable repassesVendedores = + from x in this.RepassesVendedores + where x.get_Vendedor().get_Id() == vendedor.get_Id() + select x; + if (repassesVendedores == null) + { + return null; + } + IEnumerable valueOrDefault = + from x in repassesVendedores + where x.get_Tipo().GetValueOrDefault() == 3 + select x; + if (valueOrDefault == null) + { + return null; + } + return ( + from x in valueOrDefault + orderby x.get_ValorNovo() + select x).ToList(); + } + if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 20)) + { + IEnumerable repassesVendedores1 = + from x in this.RepassesVendedores + where x.get_Vendedor().get_Id() == vendedor.get_Id() + select x; + if (repassesVendedores1 == null) + { + return null; + } + return ( + from x in repassesVendedores1 + where x.get_Tipo().GetValueOrDefault() != 3 + orderby x.get_ValorNovo() + select x).ToList(); + } + repasses = (!this.RepassesVendedores.Any((Gestor.Model.Domain.Seguros.Repasse x) => { + if (x.get_Vendedor().get_Id() != vendedor.get_Id() || x.get_Ramo() == null) + { + return false; + } + return x.get_Ramo().get_Id() == this.SelectedDocumento.get_Controle().get_Ramo().get_Id(); + }) ? this.RepassesVendedores.Where((Gestor.Model.Domain.Seguros.Repasse x) => { + if (x.get_Vendedor().get_Id() != vendedor.get_Id()) + { + return false; + } + return x.get_Ramo() == null; + }).OrderBy((Gestor.Model.Domain.Seguros.Repasse x) => x.get_ValorNovo()).ToList() : this.RepassesVendedores.Where((Gestor.Model.Domain.Seguros.Repasse x) => { + if (x.get_Vendedor().get_Id() != vendedor.get_Id() || x.get_Ramo() == null) + { + return false; + } + return x.get_Ramo().get_Id() == this.SelectedDocumento.get_Controle().get_Ramo().get_Id(); + }).OrderBy((Gestor.Model.Domain.Seguros.Repasse x) => x.get_ValorNovo()).ToList()); + return repasses; + } + + public List> HabilitarVendedor(int editarParcelaTipo = 0) + { + IEnumerable u00210s; + List> keyValuePairs = new List>(); + if (editarParcelaTipo != 4) + { + keyValuePairs.AddRange(this.SelectedDocumento.Validate(this.IsEndosso, Recursos.Configuracoes.Any((ConfiguracaoSistema c) => c.get_Configuracao() == 11))); + } + else if (this.SelectedParcela != null) + { + List> keyValuePairs1 = keyValuePairs; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela != null) + { + u00210s = selectedParcela.Validate(Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 9), Recursos.Configuracoes.Any((ConfiguracaoSistema y) => y.get_Configuracao() == 11), this.EditandoParcela, Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 16)); + } + else + { + u00210s = null; + } + keyValuePairs1.AddRange(u00210s); + } + return keyValuePairs; + } + + public async Task Importacao() + { + DateTime? dataCriacao; + DateTime? dataImportacao; + RegistroLog registroLog; + DateTime? nullable; + object nome; + string str; + object obj; + string str1; + bool flag; + string str2; + DateTime? nullable1; + object nome1; + bool flag1; + string str3; + DateTime? nullable2; + object obj1; + string str4; + string str5; + List criticaApolices = await (new CriticaApoliceServico()).BuscarImportacao(this.SelectedDocumento.get_Id()); + List list = await (new LogServico()).FindByEntityId(2, this.SelectedDocumento.get_Id()).ToList(); + if (list.Count > 0) + { + registroLog = list.Last(); + } + else + { + registroLog = null; + } + RegistroLog registroLog1 = registroLog; + switch (criticaApolices.Count) + { + case 0: + { + BaseApoliceViewModel baseApoliceViewModel = this; + dataCriacao = this.SelectedDocumento.get_DataCriacao(); + if (!dataCriacao.HasValue) + { + if (registroLog1 != null) + { + nome = registroLog1.get_Usuario().get_Nome(); + } + else + { + nome = null; + } + if (registroLog1 != null) + { + nullable = new DateTime?(registroLog1.get_DataHora()); + } + else + { + dataCriacao = null; + nullable = dataCriacao; + } + str = string.Format("CADASTRO MANUAL: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", nome, nullable); + } + else + { + Usuario usuarioCriacao = this.SelectedDocumento.get_UsuarioCriacao(); + if (usuarioCriacao != null) + { + obj = usuarioCriacao.get_Nome(); + } + else + { + obj = null; + } + str = string.Format("CADASTRO MANUAL: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", obj, this.SelectedDocumento.get_DataCriacao()); + } + baseApoliceViewModel.Importado = str; + break; + } + case 1: + { + if (string.IsNullOrWhiteSpace(criticaApolices[0].get_Tipo()) || criticaApolices[0].get_Tipo() == "0") + { + BaseApoliceViewModel baseApoliceViewModel1 = this; + str1 = (!criticaApolices[0].get_Aggilizador().HasValue || !criticaApolices[0].get_Aggilizador().Value ? string.Format("IMPORTAÇÃO DA PROPOSTA: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolices[0].get_UsuarioImportacao().get_Nome(), criticaApolices[0].get_DataImportacao()) : string.Format("IMPORTAÇÃO DA PROPOSTA VIA AGGILIZADOR: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolices[0].get_UsuarioImportacao().get_Nome(), criticaApolices[0].get_DataImportacao())); + baseApoliceViewModel1.Importado = str1; + } + if (criticaApolices[0].get_Tipo() == "1") + { + dataCriacao = this.SelectedDocumento.get_DataCriacao(); + if (dataCriacao.HasValue) + { + dataCriacao = criticaApolices[0].get_DataImportacao(); + if (dataCriacao.HasValue) + { + dataCriacao = this.SelectedDocumento.get_DataCriacao(); + DateTime value = dataCriacao.Value; + dataCriacao = criticaApolices[0].get_DataImportacao(); + if (DateTime.Compare(value, dataCriacao.Value) < 0) + { + this.Importado = string.Format("CADASTRO MANUAL DA PROPOSTA: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}\n", this.SelectedDocumento.get_UsuarioCriacao(), this.SelectedDocumento.get_DataCriacao()); + } + } + } + else + { + BaseApoliceViewModel baseApoliceViewModel2 = this; + if (registroLog1 != null) + { + obj1 = registroLog1.get_Usuario().get_Nome(); + } + else + { + obj1 = null; + } + if (registroLog1 != null) + { + nullable2 = new DateTime?(registroLog1.get_DataHora()); + } + else + { + dataCriacao = null; + nullable2 = dataCriacao; + } + baseApoliceViewModel2.Importado = string.Format("CADASTRO MANUAL DA PROPOSTA: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}\n", obj1, nullable2); + } + dataCriacao = this.SelectedDocumento.get_DataCriacao(); + dataImportacao = criticaApolices[0].get_DataImportacao(); + flag1 = (dataCriacao.HasValue & dataImportacao.HasValue ? dataCriacao.GetValueOrDefault() <= dataImportacao.GetValueOrDefault() : false); + if (flag1) + { + BaseApoliceViewModel baseApoliceViewModel3 = this; + str3 = (!criticaApolices[0].get_Aggilizador().HasValue || !criticaApolices[0].get_Aggilizador().Value ? string.Format("IMPORTAÇÃO DA APÓLICE: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolices[0].get_UsuarioImportacao().get_Nome(), criticaApolices[0].get_DataImportacao()) : string.Format("IMPORTAÇÃO DA APÓLICE VIA AGGILIZADOR: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolices[0].get_UsuarioImportacao().get_Nome(), criticaApolices[0].get_DataImportacao())); + baseApoliceViewModel3.Importado = str3; + } + } + if (criticaApolices[0].get_Tipo() != "2") + { + break; + } + dataImportacao = this.SelectedDocumento.get_DataCriacao(); + if (dataImportacao.HasValue) + { + dataImportacao = criticaApolices[0].get_DataImportacao(); + if (dataImportacao.HasValue) + { + dataImportacao = this.SelectedDocumento.get_DataCriacao(); + DateTime dateTime = dataImportacao.Value; + dataImportacao = criticaApolices[0].get_DataImportacao(); + if (DateTime.Compare(dateTime, dataImportacao.Value) < 0) + { + this.Importado = string.Format("CADASTRO MANUAL DA PROPOSTA: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}\n", this.SelectedDocumento.get_UsuarioCriacao(), this.SelectedDocumento.get_DataCriacao()); + } + } + } + else + { + BaseApoliceViewModel baseApoliceViewModel4 = this; + if (registroLog1 != null) + { + nome1 = registroLog1.get_Usuario().get_Nome(); + } + else + { + nome1 = null; + } + if (registroLog1 != null) + { + nullable1 = new DateTime?(registroLog1.get_DataHora()); + } + else + { + dataImportacao = null; + nullable1 = dataImportacao; + } + baseApoliceViewModel4.Importado = string.Format("CADASTRO MANUAL DA PROPOSTA: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}\n", nome1, nullable1); + } + dataImportacao = this.SelectedDocumento.get_DataCriacao(); + dataCriacao = criticaApolices[0].get_DataImportacao(); + flag = (dataImportacao.HasValue & dataCriacao.HasValue ? dataImportacao.GetValueOrDefault() <= dataCriacao.GetValueOrDefault() : false); + if (!flag) + { + break; + } + BaseApoliceViewModel baseApoliceViewModel5 = this; + str2 = (!criticaApolices[0].get_Aggilizador().HasValue || !criticaApolices[0].get_Aggilizador().Value ? string.Format("IMPORTAÇÃO DO ENDOSSO: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolices[0].get_UsuarioImportacao().get_Nome(), criticaApolices[0].get_DataImportacao()) : string.Format("IMPORTAÇÃO DO ENDOSSO VIA AGGILIZADOR: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolices[0].get_UsuarioImportacao().get_Nome(), criticaApolices[0].get_DataImportacao())); + baseApoliceViewModel5.Importado = str2; + break; + } + case 2: + case 3: + { + List criticaApolices1 = criticaApolices; + CriticaApolice criticaApolouse = criticaApolices1.Find((CriticaApolice x) => { + if (string.IsNullOrWhiteSpace(x.get_Tipo())) + { + return true; + } + return x.get_Tipo() == "0"; + }); + List criticaApolices2 = criticaApolices; + CriticaApolice criticaApolouse1 = criticaApolices2.Find((CriticaApolice x) => x.get_Tipo() == "1"); + BaseApoliceViewModel baseApoliceViewModel6 = this; + str4 = (!criticaApolouse.get_Aggilizador().HasValue || !criticaApolouse.get_Aggilizador().Value ? string.Format("IMPORTAÇÃO DA PROPOSTA: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}\n", criticaApolouse.get_UsuarioImportacao().get_Nome(), criticaApolouse.get_DataImportacao()) : string.Format("IMPORTAÇÃO DA PROPOSTA VIA AGGILIZADOR: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}\n", criticaApolouse.get_UsuarioImportacao().get_Nome(), criticaApolouse.get_DataImportacao())); + baseApoliceViewModel6.Importado = str4; + if (criticaApolouse1 == null) + { + break; + } + BaseApoliceViewModel baseApoliceViewModel7 = this; + string importado = this.Importado; + str5 = (!criticaApolouse1.get_Aggilizador().HasValue || !criticaApolouse1.get_Aggilizador().Value ? string.Format("IMPORTAÇÃO DA APÓLICE: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolouse1.get_UsuarioImportacao().get_Nome(), criticaApolouse1.get_DataImportacao()) : string.Format("IMPORTAÇÃO DA APÓLICE VIA AGGILIZADOR: {0} - {1:dd/MM/yyyy 'ÀS' HH:mm:ss}", criticaApolouse1.get_UsuarioImportacao().get_Nome(), criticaApolouse1.get_DataImportacao())); + baseApoliceViewModel7.Importado = string.Concat(importado, str5); + break; + } + } + criticaApolices = null; + } + + public async Task IncluirApolice(bool renovar = false) + { + bool flag; + DateTime? emissao; + FormaPagamento? nullable1; + List list; + List vendedors; + DateTime dateTime; + ObservableCollection observableCollection; + Documento documento; + if (renovar) + { + if (!string.IsNullOrWhiteSpace(this.SelectedDocumento.get_Apolice())) + { + emissao = this.SelectedDocumento.get_Emissao(); + if (emissao.HasValue) + { + goto Label1; + } + } + await base.ShowMessage("PROPOSTA NÃO PODE SER RENOVADA. NECESSÁRIO PREENCHER O NÚMERO DA APÓLICE E DATA DE EMISSÃO ANTES DE PROSSEGUIR.", "OK", "", false); + flag = false; + documento = null; + return flag; + } + Label1: + List seguradoras = Recursos.Seguradoras; + IEnumerable ativo = + from x in seguradoras + where x.get_Ativo() + select x; + List list1 = ( + from x in ativo + orderby x.get_Nome() + select x).ToList(); + this.Seguradoras = list1; + this.SeguradorasAnteriores = Recursos.Seguradoras; + List ramos = Recursos.Ramos; + IEnumerable ativo1 = + from x in ramos + where x.get_Ativo() + select x; + List ramos1 = ( + from x in ativo1 + orderby x.get_Nome() + select x).ToList(); + this.Ramos = ramos1; + List produtos = Recursos.Produtos; + List produtos1 = ( + from x in produtos + where x.get_Ativo() + select x).ToList(); + this.Produtos = produtos1; + List status = Recursos.Status; + List statuses = ( + from x in status + where x.get_Ativo() + select x).ToList(); + this.Status = statuses; + DateTime date = Funcoes.GetNetworkTime().Date; + if (!renovar) + { + this.Inclusao = true; + BaseApoliceViewModel baseApoliceViewModel = this; + List configuracoes = Recursos.Configuracoes; + if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 20)) + { + List todosVendedores = this.TodosVendedores; + list = todosVendedores.Where((Vendedor x) => { + if (x.get_IdEmpresa() != MainViewModel.ClienteSelecionado.get_IdEmpresa() || !x.get_Ativo()) + { + return false; + } + return !x.get_Corretora(); + }).ToList(); + } + else + { + list = new List(); + } + baseApoliceViewModel.Vendedores = list; + BaseApoliceViewModel baseApoliceViewModel1 = this; + List estipulantes = Recursos.Estipulantes; + baseApoliceViewModel1.Estipulantes = estipulantes.Where((Estipulante x) => { + if (x.get_IdEmpresa() != MainViewModel.ClienteSelecionado.get_IdEmpresa()) + { + return false; + } + return x.get_Ativo(); + }).ToList(); + Documento documento1 = new Documento(); + Controle controle = new Controle(); + controle.set_Cliente(MainViewModel.ClienteSelecionado); + controle.set_IdEmpresa(MainViewModel.ClienteSelecionado.get_IdEmpresa()); + documento1.set_Controle(controle); + documento1.set_Ordem(0); + documento1.set_Tipo(0); + documento1.set_NegocioCorretora(new NegocioCorretora?(0)); + documento1.set_Situacao(1); + documento1.set_TipoRecebimento(new TipoRecebimento?(1)); + documento1.set_Vigencia1(date); + documento1.set_Vigencia2(new DateTime?(date.AddYears(1))); + documento1.set_ApoliceConferida(false); + documento1.set_PropostaAssinada(false); + documento1.set_AdicionalComiss(false); + documento1.set_Excluido(false); + nullable1 = null; + documento1.set_FormaPagamento(nullable1); + documento = documento1; + this.Pagamentos = null; + this.Repasses = null; + } + else + { + this.SelectedDocumento = await this.Servico.BuscarApoliceAsync(this.SelectedDocumento.get_Id(), false, false); + this.DocumentoRenovado = this.SelectedDocumento; + if (this.Seguradoras.All((Seguradora x) => x.get_Id() != this.SelectedDocumento.get_Controle().get_Seguradora().get_Id())) + { + this.Seguradoras.Add(this.SelectedDocumento.get_Controle().get_Seguradora()); + } + if (this.SelectedDocumento.get_Controle().get_Produto() != null && this.Produtos.All((Produto x) => x.get_Id() != this.SelectedDocumento.get_Controle().get_Produto().get_Id())) + { + this.Seguradoras.Add(this.SelectedDocumento.get_Controle().get_Seguradora()); + } + if (this.SelectedDocumento.get_Controle().get_Ramo() != null && this.Ramos.All((Ramo x) => x.get_Id() != this.SelectedDocumento.get_Controle().get_Ramo().get_Id())) + { + this.Seguradoras.Add(this.SelectedDocumento.get_Controle().get_Seguradora()); + } + BaseApoliceViewModel baseApoliceViewModel2 = this; + List configuracaoSistemas = Recursos.Configuracoes; + vendedors = (configuracaoSistemas.All((ConfiguracaoSistema x) => x.get_Configuracao() != 20) ? this.TodosVendedores.Where((Vendedor x) => { + if (x.get_IdEmpresa() != this.SelectedDocumento.get_Controle().get_IdEmpresa() || !x.get_Ativo()) + { + return false; + } + return !x.get_Corretora(); + }).ToList() : new List()); + baseApoliceViewModel2.Vendedores = vendedors; + this.Estipulantes = Recursos.Estipulantes.Where((Estipulante x) => { + if (x.get_IdEmpresa() != this.SelectedDocumento.get_Controle().get_IdEmpresa()) + { + return false; + } + return x.get_Ativo(); + }).ToList(); + Documento documento2 = new Documento(); + Controle controle1 = new Controle(); + controle1.set_Cliente(MainViewModel.ClienteSelecionado); + controle1.set_IdEmpresa(this.SelectedDocumento.get_Controle().get_IdEmpresa()); + controle1.set_Ramo(this.SelectedDocumento.get_Controle().get_Ramo()); + controle1.set_Seguradora(this.SelectedDocumento.get_Controle().get_Seguradora()); + controle1.set_SeguradoraAnterior(this.SelectedDocumento.get_Controle().get_Seguradora()); + documento2.set_Controle(controle1); + documento2.set_Ordem(0); + documento2.set_Tipo(0); + documento2.set_NegocioCorretora(new NegocioCorretora?(1)); + documento2.set_Situacao(2); + documento2.set_Negocio(new Negocio?(1)); + documento2.set_TipoRecebimento(new TipoRecebimento?(1)); + emissao = this.SelectedDocumento.get_Vigencia2(); + documento2.set_Vigencia1(emissao.GetValueOrDefault(date)); + emissao = this.SelectedDocumento.get_Vigencia2(); + dateTime = (emissao.HasValue ? emissao.GetValueOrDefault().AddYears(1) : date.AddYears(1)); + documento2.set_Vigencia2(new DateTime?(dateTime)); + documento2.set_ApoliceConferida(false); + documento2.set_PropostaAssinada(false); + documento2.set_AdicionalComiss(false); + documento2.set_Excluido(false); + documento2.set_ApoliceAnterior(this.SelectedDocumento.get_Apolice()); + nullable1 = null; + documento2.set_FormaPagamento(nullable1); + documento = documento2; + this.EmissaoDocumento = new DateTime?(date); + this.TransmissaoDocumento = new DateTime?(date); + if (!await base.ShowMessage("DESEJA MANTER OS VENDEDORES DA APÓLICE ANTERIOR?", "SIM", "NÃO", false)) + { + this.Pagamentos = new ObservableCollection() + { + this.PropriaCorretora() + }; + this.Repasses = null; + } + else + { + ObservableCollection pagamentos = this.Pagamentos; + if (pagamentos != null) + { + List vendedorParcelas = pagamentos.ToList(); + vendedorParcelas.ForEach((VendedorParcela x) => { + x.set_Documento(null); + x.set_ValorRepasse(new decimal?(new decimal())); + x.set_ValorTotal(null); + DateTime? nullable = null; + x.set_DataPagamento(nullable); + nullable = null; + x.set_DataPagamento(nullable); + }); + } + else + { + } + } + BaseApoliceViewModel baseApoliceViewModel3 = this; + observableCollection = (this.Pagamentos != null ? new ObservableCollection(this.Pagamentos) : new ObservableCollection()); + baseApoliceViewModel3.Pagamentos = observableCollection; + } + this.IsFatura = false; + this.SelectedParcela = null; + this.SelectedDocumento = null; + this.SelectedPagamento = null; + this.Parcelas = null; + this.SelectedDocumento = documento; + this.IsEndosso = false; + this.NovaApolice = true; + this.Renovar = renovar; + this.EnableAlterarSituacao = true; + this.AllowEditVendedor = !renovar; + this.AllowEditApolice = true; + base.IsEnabledEdit = true; + base.IsEnabledEditEndosso = true; + base.AllowEditParcela = false; + base.EnableFields = true; + base.EnableIncluir = false; + Action enableMainMenu = Gestor.Application.Actions.Actions.EnableMainMenu; + if (enableMainMenu != null) + { + enableMainMenu(false); + } + else + { + } + flag = true; + documento = null; + return flag; + } + + public async Task IncluirEndosso() + { + bool flag; + ObservableCollection observableCollection; + NegocioCorretora valueOrDefault; + TipoEndosso tipoEndosso; + List configuracoes = Recursos.Configuracoes; + if (configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 13) || !string.IsNullOrWhiteSpace(this.SelectedDocumento.get_Apolice())) + { + if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2) + { + observableCollection = new ObservableCollection(new List() + { + 2, + 1, + 4 + }); + } + else + { + List tipoEndossos = new List() + { + 0, + 1, + 2, + 4 + }; + observableCollection = new ObservableCollection(tipoEndossos); + } + ObservableCollection observableCollection1 = observableCollection; + if (this.SelectedDocumento.get_Situacao() == 3) + { + observableCollection1 = new ObservableCollection(new List() + { + 3 + }); + } + this.TipoEndossoList = observableCollection1; + Documento documento = new Documento(); + documento.set_Controle(this.SelectedDocumento.get_Controle()); + documento.set_Tipo(1); + IList documentos = this.SelectedDocumento.get_Controle().get_Documentos(); + IEnumerable excluido = + from x in documentos + where !x.get_Excluido() + select x; + documento.set_Ordem(excluido.Max((Documento x) => x.get_Ordem()) + 1); + NegocioCorretora? negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + if (negocioCorretora.HasValue) + { + valueOrDefault = negocioCorretora.GetValueOrDefault(); + } + else + { + valueOrDefault = (this.SelectedDocumento.get_Situacao() != 2 || !this.SelectedDocumento.get_Negocio().HasValue || this.SelectedDocumento.get_Negocio().GetValueOrDefault() != 1 ? 0 : 1); + } + documento.set_NegocioCorretora(new NegocioCorretora?(valueOrDefault)); + documento.set_Situacao(this.SelectedDocumento.get_Situacao()); + documento.set_Negocio(this.SelectedDocumento.get_Negocio()); + documento.set_TipoRecebimento(this.SelectedDocumento.get_TipoRecebimento()); + documento.set_Vigencia1(Funcoes.GetNetworkTime().Date); + documento.set_Vigencia2(this.SelectedDocumento.get_Vigencia2()); + documento.set_ApoliceConferida(false); + documento.set_PropostaAssinada(false); + documento.set_AdicionalComiss(false); + documento.set_Excluido(false); + documento.set_Apolice(this.SelectedDocumento.get_Apolice()); + documento.set_Proposta(this.SelectedDocumento.get_Proposta()); + tipoEndosso = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? 2 : 0); + documento.set_TipoEndosso(new TipoEndosso?(tipoEndosso)); + documento.set_Comissao(this.SelectedDocumento.get_Comissao()); + documento.set_Estipulante1(this.SelectedDocumento.get_Estipulante1()); + documento.set_Estipulante2(this.SelectedDocumento.get_Estipulante2()); + documento.set_Estipulante3(this.SelectedDocumento.get_Estipulante3()); + documento.set_Estipulante4(this.SelectedDocumento.get_Estipulante4()); + documento.set_Estipulante5(this.SelectedDocumento.get_Estipulante5()); + Documento documento1 = documento; + this.SelectedParcela = null; + this.SelectedDocumento = null; + this.SelectedPagamento = null; + if (documento1.get_TipoRecebimento().GetValueOrDefault() != 1) + { + this.Pagamentos = null; + this.Repasses = null; + } + else + { + List repasses = this.Repasses; + List list = ( + from x in repasses + where x.get_Parcela().get_SubTipo() == 1 + select x).ToList(); + List vendedorParcelas = ( + from x in list + group x by x.get_Vendedor().get_Id()).Select, VendedorParcela>((IGrouping x) => { + VendedorParcela vendedorParcela = new VendedorParcela(); + vendedorParcela.set_Repasse(x.First().get_Repasse()); + vendedorParcela.set_Parcela(this.SelectedParcela); + vendedorParcela.set_Documento(this.SelectedDocumento); + vendedorParcela.set_ValorRepasse(new decimal?(new decimal())); + vendedorParcela.set_Vendedor(x.First().get_Vendedor()); + vendedorParcela.set_PorcentagemRepasse(x.First().get_PorcentagemRepasse()); + vendedorParcela.set_TipoVendedor(x.First().get_TipoVendedor()); + return vendedorParcela; + }).ToList(); + this.Pagamentos = new ObservableCollection(vendedorParcelas); + this.Repasses = vendedorParcelas; + } + this.Parcelas = null; + this.SelectedDocumento = documento1; + this.NovaApolice = true; + this.AllowEditVendedor = false; + this.AllowEditApolice = true; + this.IsEndosso = true; + base.IsEnabledEditEndosso = true; + base.EnableFields = true; + base.EnableIncluir = false; + this.AllowEditEmissao = true; + Action enableMainMenu = Gestor.Application.Actions.Actions.EnableMainMenu; + if (enableMainMenu != null) + { + enableMainMenu(false); + } + else + { + } + flag = true; + } + else + { + await base.ShowMessage("PROPOSTA NÃO PODE SER ENDOSSADA. NECESSÁRIO PREENCHER O NÚMERO DA APÓLICE E DATA DE EMISSÃO ANTES DE PROSSEGUIR.", "OK", "", false); + flag = false; + } + return flag; + } + + public void IncluirFatura() + { + long? nullable1; + int numeroParcela; + decimal comissao; + long id; + long? nullable2; + Parcela parcela = ( + from x in this.Parcelas + orderby x.get_NumeroParcela() + select x).LastOrDefault((Parcela x) => x.get_SubTipo() == 1); + if (parcela != null) + { + numeroParcela = parcela.get_NumeroParcela(); + } + else + { + numeroParcela = 0; + } + int num = numeroParcela + 1; + if (parcela != null) + { + comissao = parcela.get_Comissao(); + } + else + { + comissao = decimal.Zero; + } + decimal num1 = comissao; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela != null) + { + id = selectedParcela.get_Id(); + } + else + { + ObservableCollection parcelas = this.Parcelas; + if (parcelas != null) + { + Parcela parcela1 = ( + from x in parcelas + orderby x.get_NumeroParcela() + select x).LastOrDefault((Parcela x) => x.get_SubTipo() == 1); + if (parcela1 != null) + { + nullable2 = new long?(parcela1.get_Id()); + } + else + { + nullable1 = null; + nullable2 = nullable1; + } + } + else + { + nullable1 = null; + nullable2 = nullable1; + } + nullable1 = nullable2; + id = nullable1.GetValueOrDefault(); + } + long num2 = id; + DateTime networkTime = Funcoes.GetNetworkTime(); + Parcela parcela2 = new Parcela(); + parcela2.set_IdEmpresa(this.SelectedDocumento.get_Controle().get_IdEmpresa()); + parcela2.set_Documento(this.SelectedDocumento); + parcela2.set_Vencimento(Funcoes.GetNetworkTime().Date); + parcela2.set_Comissao(num1); + parcela2.set_SubTipo(1); + parcela2.set_NumeroParcela(num); + parcela2.set_DataCriacao(new DateTime?(networkTime)); + parcela2.set_UsuarioCriacao(Recursos.Usuario.get_Id()); + this.SelectedParcela = parcela2; + if (num2 == 0) + { + return; + } + List list = ( + from x in this.Repasses + where x.get_Parcela().get_Id() == num2 + select x).ToList(); + list.ForEach((VendedorParcela x) => { + decimal zero; + x.set_Id((long)0); + x.set_Parcela(this.SelectedParcela); + DateTime? nullable = null; + x.set_DataPrePagamento(nullable); + nullable = null; + x.set_DataPagamento(nullable); + VendedorParcela vendedorParcela = x; + if (x.get_Repasse() != null) + { + NegocioCorretora? negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + zero = (negocioCorretora.GetValueOrDefault() == 0 & negocioCorretora.HasValue ? x.get_Repasse().get_ValorNovo() : x.get_Repasse().get_ValorRenovacao()); + } + else + { + zero = decimal.Zero; + } + vendedorParcela.set_PorcentagemRepasse(new decimal?(zero)); + }); + this.Repasses = list; + this.RecalculaRepasse(); + } + + public void IncluirParcelaEspecial() + { + Parcela parcela; + Parcela parcela1 = new Parcela(); + parcela1.set_IdEmpresa(this.SelectedDocumento.get_Controle().get_IdEmpresa()); + parcela1.set_Documento(this.SelectedDocumento); + parcela1.set_Vencimento(Funcoes.GetNetworkTime().Date); + parcela1.set_Comissao(new decimal(100)); + parcela1.set_SubTipo(3); + parcela1.set_NumeroParcela(999); + parcela1.set_DataCriacao(new DateTime?(Funcoes.GetNetworkTime())); + parcela1.set_UsuarioCriacao(Recursos.Usuario.get_Id()); + this.SelectedParcela = parcela1; + ObservableCollection parcelas = this.Parcelas; + if (parcelas != null) + { + parcela = parcelas.FirstOrDefault((Parcela x) => x.get_SubTipo() == 1); + } + else + { + parcela = null; + } + Parcela parcela2 = parcela; + if (parcela2 == null) + { + this.Repasses = new List(); + return; + } + List list = ( + from x in this.Repasses + where x.get_Parcela().get_Id() == parcela2.get_Id() + select x).ToList(); + list.ForEach((VendedorParcela x) => { + x.set_Id((long)0); + x.set_Parcela(this.SelectedParcela); + DateTime? nullable = null; + x.set_DataPrePagamento(nullable); + nullable = null; + x.set_DataPagamento(nullable); + x.set_ValorRepasse(new decimal?(new decimal())); + nullable = null; + x.set_DataPagamento(nullable); + }); + this.Repasses = list; + this.RecalculaRepasse(); + } + + private async Task IncluirPropriaCorretora() + { + VendedorParcela vendedorParcela; + Parcela selectedParcela; + if (this.Parcelas.Count != 0) + { + VendedorParcela vendedorParcela1 = this.PropriaCorretora(); + if (this.SelectedParcela.get_SubTipo() != 1 || this.IsFatura) + { + selectedParcela = this.SelectedParcela; + } + else + { + ObservableCollection parcelas = this.Parcelas; + selectedParcela = parcelas.FirstOrDefault((Parcela x) => x.get_NumeroParcela() == 1); + } + Parcela parcela = selectedParcela; + vendedorParcela1.set_Parcela(parcela); + vendedorParcela1.set_Documento(this.SelectedDocumento); + if (parcela == null || parcela.get_Id() != 0) + { + vendedorParcela = await this.Servico.IncluirVendedor(vendedorParcela1); + } + else + { + vendedorParcela = vendedorParcela1; + } + } + else + { + vendedorParcela = null; + } + return vendedorParcela; + } + + public void IncluirVendedor() + { + VendedorParcela vendedorParcela = new VendedorParcela(); + vendedorParcela.set_Documento(this.SelectedDocumento); + this.SelectedPagamento = vendedorParcela; + } + + public async Task LimparRepasses() + { + bool count; + bool flag; + if (this.Pagamentos != null) + { + ObservableCollection pagamentos = this.Pagamentos; + if (pagamentos != null) + { + count = pagamentos.Count == 0; + } + else + { + count = false; + } + if (!count && this.Repasses != null) + { + List repasses = this.Repasses; + if (repasses != null) + { + flag = repasses.Count == 0; + } + else + { + flag = false; + } + if (!flag && this.SelectedDocumento.get_Id() == 0) + { + if (!base.EnableFields || !this.AllowEditApolice || !this.AlteracaoEnabled) + { + return; + } + else + { + await base.ShowMessage("REPASSES ADICIONADOS NÃO PERTENCEM AO RAMO SELECIONADO E SERÃO EXCLUÍDOS.", "OK", "", false); + this.Pagamentos.Clear(); + this.Repasses.Clear(); + return; + } + } + } + } + } + + public void ManutecaoItens() + { + if (!this.Invoke) + { + return; + } + Action acessaTela = Gestor.Application.Actions.Actions.AcessaTela; + if (acessaTela == null) + { + return; + } + acessaTela(3, "Manutencao"); + } + + public async Task PagamentoVendedor(Parcela parcela) + { + return await this.ParcelaServico.TemPagamento(parcela.get_Id()); + } + + private void PreLoad() + { + this.Ramos = Recursos.Ramos; + this.Seguradoras = Recursos.Seguradoras; + this.Produtos = Recursos.Produtos; + this.Status = Recursos.Status; + this.SeguradorasAnteriores = Recursos.Seguradoras; + this.TipoEndossoList = new ObservableCollection(new List() + { + 0, + 1, + 2, + 4, + 3 + }); + } + + private VendedorParcela PropriaCorretora() + { + VendedorParcela vendedorParcela = new VendedorParcela(); + vendedorParcela.set_Repasse(null); + decimal num = new decimal(); + vendedorParcela.set_ValorRepasse(new decimal?(num)); + vendedorParcela.set_Documento(this.SelectedDocumento); + vendedorParcela.set_Vendedor(Recursos.Vendedores.FirstOrDefault((Vendedor x) => { + long? nullable; + long? nullable1; + long idEmpresa = x.get_IdEmpresa(); + Documento selectedDocumento = this.SelectedDocumento; + if (selectedDocumento != null) + { + Controle controle = selectedDocumento.get_Controle(); + if (controle != null) + { + nullable1 = new long?(controle.get_IdEmpresa()); + } + else + { + nullable = null; + nullable1 = nullable; + } + } + else + { + nullable = null; + nullable1 = nullable; + } + long? nullable2 = nullable1; + if (idEmpresa != (nullable2.HasValue ? nullable2.GetValueOrDefault() : Recursos.Empresa.get_Id())) + { + return false; + } + return x.get_Corretora(); + })); + num = new decimal(); + vendedorParcela.set_PorcentagemRepasse(new decimal?(num)); + vendedorParcela.set_TipoVendedor(Recursos.TipoVendedor.First((TipoVendedor x) => x.get_Id() == (long)1)); + return vendedorParcela; + } + + public void RecalculaRepasse() + { + List list; + if (!this.IsFatura && this.BaixarParcelas && this.SelectedParcela.get_SubTipo() == 1) + { + return; + } + if (this.Repasses == null || this.Repasses.Count == 0) + { + return; + } + if (this.SelectedParcela.get_Id() == 0) + { + this.Repasses.ForEach((VendedorParcela x) => { + decimal? porcentagemRepasse; + bool valueOrDefault; + decimal? nullable; + bool flag; + if (x.get_DataPagamento().HasValue) + { + return; + } + Gestor.Model.Domain.Seguros.Repasse repasse = x.get_Repasse(); + valueOrDefault = (repasse != null ? repasse.get_Tipo().GetValueOrDefault() == 3 : false); + if (valueOrDefault) + { + return; + } + Parcela parcela = x.get_Parcela() ?? this.SelectedParcela; + parcela.set_Documento(this.SelectedDocumento); + if (x.get_Repasse() != null) + { + Gestor.Model.Domain.Seguros.Repasse repasse1 = x.get_Repasse(); + porcentagemRepasse = x.get_PorcentagemRepasse(); + repasse1.set_ValorNovo((porcentagemRepasse.HasValue ? porcentagemRepasse.GetValueOrDefault() : x.get_Repasse().get_ValorNovo())); + Gestor.Model.Domain.Seguros.Repasse repasse2 = x.get_Repasse(); + porcentagemRepasse = x.get_PorcentagemRepasse(); + repasse2.set_ValorRenovacao((porcentagemRepasse.HasValue ? porcentagemRepasse.GetValueOrDefault() : x.get_Repasse().get_ValorRenovacao())); + } + decimal num = Funcoes.CalculaRepasse(x.get_Repasse(), parcela, true); + VendedorParcela vendedorParcela = x; + if (this.SelectedDocumento.get_NumeroParcelas() > decimal.Zero && !this.SelectedParcela.get_NumeroParcela().Equals(999)) + { + Gestor.Model.Domain.Seguros.Repasse repasse3 = x.get_Repasse(); + flag = (repasse3 != null ? repasse3.get_Forma().GetValueOrDefault() == 3 : false); + if (!flag) + { + nullable = new decimal?(num); + vendedorParcela.set_ValorRepasse(nullable); + x.set_ValorTotal(new decimal?(num)); + return; + } + porcentagemRepasse = x.get_ValorTotal(); + decimal numeroParcelas = this.SelectedDocumento.get_NumeroParcelas(); + if (porcentagemRepasse.HasValue) + { + nullable = new decimal?(porcentagemRepasse.GetValueOrDefault() / numeroParcelas); + vendedorParcela.set_ValorRepasse(nullable); + x.set_ValorTotal(new decimal?(num)); + return; + } + else + { + nullable = null; + vendedorParcela.set_ValorRepasse(nullable); + x.set_ValorTotal(new decimal?(num)); + return; + } + } + nullable = new decimal?(num); + vendedorParcela.set_ValorRepasse(nullable); + x.set_ValorTotal(new decimal?(num)); + }); + this.Pagamentos = new ObservableCollection(this.Repasses); + return; + } + List repasses = this.Repasses; + if (repasses != null) + { + repasses.Where((VendedorParcela x) => { + if (this.SelectedParcela.get_Id() <= (long)0) + { + return false; + } + return x.get_Parcela().get_Id() == this.SelectedParcela.get_Id(); + }).ToList().ForEach((VendedorParcela x) => { + decimal? porcentagemRepasse; + bool valueOrDefault; + decimal? nullable; + VendedorParcela vendedorParcela; + decimal? nullable1; + bool flag; + if (x.get_DataPagamento().HasValue) + { + return; + } + Gestor.Model.Domain.Seguros.Repasse repasse = x.get_Repasse(); + valueOrDefault = (repasse != null ? repasse.get_Tipo().GetValueOrDefault() == 3 : false); + if (valueOrDefault) + { + return; + } + Parcela selectedParcela = this.SelectedParcela; + selectedParcela.set_Documento(this.SelectedDocumento); + if (x.get_Repasse() != null) + { + Gestor.Model.Domain.Seguros.Repasse repasse1 = x.get_Repasse(); + porcentagemRepasse = x.get_PorcentagemRepasse(); + repasse1.set_ValorNovo((porcentagemRepasse.HasValue ? porcentagemRepasse.GetValueOrDefault() : x.get_Repasse().get_ValorNovo())); + Gestor.Model.Domain.Seguros.Repasse repasse2 = x.get_Repasse(); + porcentagemRepasse = x.get_PorcentagemRepasse(); + repasse2.set_ValorRenovacao((porcentagemRepasse.HasValue ? porcentagemRepasse.GetValueOrDefault() : x.get_Repasse().get_ValorRenovacao())); + } + decimal num = Funcoes.CalculaRepasse(x.get_Repasse(), selectedParcela, true); + VendedorParcela vendedorParcela1 = x; + if (this.SelectedDocumento.get_NumeroParcelas() > decimal.Zero && !this.SelectedParcela.get_NumeroParcela().Equals(999)) + { + Gestor.Model.Domain.Seguros.Repasse repasse3 = x.get_Repasse(); + flag = (repasse3 != null ? repasse3.get_Forma().GetValueOrDefault() == 3 : false); + if (!flag) + { + nullable = new decimal?(num); + vendedorParcela1.set_ValorRepasse(nullable); + vendedorParcela = x; + nullable1 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 1 || this.SelectedParcela.get_SubTipo() != 1 ? x.get_ValorTotal() : new decimal?(num)); + vendedorParcela.set_ValorTotal(nullable1); + return; + } + porcentagemRepasse = x.get_ValorTotal(); + decimal numeroParcelas = this.SelectedDocumento.get_NumeroParcelas(); + if (porcentagemRepasse.HasValue) + { + nullable = new decimal?(porcentagemRepasse.GetValueOrDefault() / numeroParcelas); + vendedorParcela1.set_ValorRepasse(nullable); + vendedorParcela = x; + nullable1 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 1 || this.SelectedParcela.get_SubTipo() != 1 ? x.get_ValorTotal() : new decimal?(num)); + vendedorParcela.set_ValorTotal(nullable1); + return; + } + else + { + nullable = null; + vendedorParcela1.set_ValorRepasse(nullable); + vendedorParcela = x; + nullable1 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 1 || this.SelectedParcela.get_SubTipo() != 1 ? x.get_ValorTotal() : new decimal?(num)); + vendedorParcela.set_ValorTotal(nullable1); + return; + } + } + nullable = new decimal?(num); + vendedorParcela1.set_ValorRepasse(nullable); + vendedorParcela = x; + nullable1 = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 1 || this.SelectedParcela.get_SubTipo() != 1 ? x.get_ValorTotal() : new decimal?(num)); + vendedorParcela.set_ValorTotal(nullable1); + }); + } + else + { + } + List vendedorParcelas = this.Repasses; + if (vendedorParcelas != null) + { + list = vendedorParcelas.Where((VendedorParcela x) => { + if (this.SelectedParcela.get_Id() <= (long)0) + { + return false; + } + return x.get_Parcela().get_Id() == this.SelectedParcela.get_Id(); + }).ToList(); + } + else + { + list = null; + } + this.Pagamentos = new ObservableCollection(list); + } + + public async void RecalculaRepasses() + { + bool flag; + if (this.Repasses != null) + { + if (this.SelectedDocumento.get_NegocioCorretora().HasValue) + { + NegocioCorretora? negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + flag = negocioCorretora.GetValueOrDefault() == 1; + } + else if (this.SelectedDocumento.get_Situacao() != 2 || !this.SelectedDocumento.get_Negocio().HasValue) + { + flag = false; + } + else + { + Negocio? negocio = this.SelectedDocumento.get_Negocio(); + flag = negocio.GetValueOrDefault() == 1; + } + bool flag1 = flag; + List repasses = this.Repasses; + if (repasses != null) + { + repasses.Where((VendedorParcela x) => { + if (this.NovaApolice) + { + return true; + } + return x.get_Parcela().get_SubTipo() == 1; + }).ToList().ForEach((VendedorParcela x) => { + decimal? valorTotal; + decimal numeroParcelas; + decimal? nullable; + decimal valorRenovacao; + decimal? nullable1; + decimal? nullable2; + decimal? nullable3; + bool valueOrDefault; + if (x.get_Parcela() == null) + { + return; + } + if (x.get_Repasse() == null) + { + return; + } + if (x.get_DataPagamento().HasValue) + { + return; + } + Parcela parcela = x.get_Parcela(); + parcela.set_Documento(this.SelectedDocumento); + decimal num = Funcoes.CalculaRepasse(x.get_Repasse(), parcela, true); + VendedorParcela vendedorParcela = x; + if (flag1) + { + Gestor.Model.Domain.Seguros.Repasse repasse = x.get_Repasse(); + valueOrDefault = (repasse != null ? repasse.get_Tipo().GetValueOrDefault() != 3 : true); + if (!valueOrDefault) + { + goto Label1; + } + valorRenovacao = x.get_Repasse().get_ValorRenovacao(); + goto Label0; + } + Label1: + valorRenovacao = x.get_Repasse().get_ValorNovo(); + Label0: + vendedorParcela.set_PorcentagemRepasse(new decimal?(valorRenovacao)); + if (x.get_Repasse().get_Forma().GetValueOrDefault() == 3) + { + valorTotal = x.get_ValorTotal(); + numeroParcelas = this.SelectedDocumento.get_NumeroParcelas(); + if (valorTotal.HasValue) + { + nullable1 = new decimal?(valorTotal.GetValueOrDefault() / numeroParcelas); + } + else + { + nullable = null; + nullable1 = nullable; + } + } + else + { + nullable1 = new decimal?(num); + } + decimal? nullable4 = nullable1; + if (x.get_CoCorretagem()) + { + numeroParcelas = this.SelectedDocumento.get_PremioLiquido(); + decimal? comissaoTotal = this.SelectedDocumento.get_ComissaoTotal(); + decimal comissao = this.SelectedDocumento.get_Comissao(); + nullable = (comissaoTotal.HasValue ? new decimal?(comissaoTotal.GetValueOrDefault() - comissao) : null); + decimal num1 = 100; + if (nullable.HasValue) + { + nullable2 = new decimal?(nullable.GetValueOrDefault() / num1); + } + else + { + comissaoTotal = null; + nullable2 = comissaoTotal; + } + valorTotal = nullable2; + if (valorTotal.HasValue) + { + nullable3 = new decimal?(numeroParcelas * valorTotal.GetValueOrDefault()); + } + else + { + nullable = null; + nullable3 = nullable; + } + nullable4 = nullable3; + } + x.set_ValorRepasse(nullable4); + x.set_ValorTotal(new decimal?(num)); + }); + } + else + { + } + if (!this.NovaApolice) + { + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela == null) + { + selectedParcela = this.Parcelas.FirstOrDefault(); + } + await baseApoliceViewModel.SelecionaParcela(selectedParcela); + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + } + else + { + BaseApoliceViewModel observableCollection = this; + List vendedorParcelas = this.Repasses; + observableCollection.Pagamentos = new ObservableCollection( + from x in vendedorParcelas + orderby x.get_TipoVendedor().get_Id() + select x); + } + } + } + + public async Task RecusarApolice() + { + bool flag; + IList list; + string str; + string str1; + string str2; + if (this.SelectedDocumento != null) + { + bool[] flagArray = await Funcoes.VerificarPagamento(this.SelectedDocumento.get_Id()); + List configuracoes = Recursos.Configuracoes; + if (configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 23)) + { + bool[] flagArray1 = flagArray; + if (((IEnumerable)flagArray1).Any((bool x) => x)) + { + await base.ShowMessage("NÃO É POSSÍVEL RECURSAR UM APÓLICE ENQUANTO HOUVER RECEBIMENTO DE COMISSÃO OU PAGAMENTO DE VENDEDORES PARA A APÓLICE", "OK", "", false); + str2 = null; + return; + } + } + List configuracaoSistemas = Recursos.Configuracoes; + flag = (!configuracaoSistemas.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 23) ? false : flagArray[1]); + bool flag1 = flag; + if (flag1) + { + flag1 = await base.ShowMessage("EXISTEM PAGAMENTOS PARA OS VENDEDORES DO CONTRATO, DESEJA CRIAR ESTORNOS PARA ESSES PAGAMENTOS?", "SIM", "NÃO", false); + } + bool flag2 = flag1; + Documento documento = await this.Servico.BuscarApoliceAsync(this.DocumentoSelecionado.get_Id(), false, false); + if (documento.get_Controle().get_Documentos().Count > 1) + { + IList documentos = documento.get_Controle().get_Documentos(); + IEnumerable excluido = + from x in documentos + where !x.get_Excluido() + select x; + list = ( + from x in excluido + orderby x.get_Ordem() + select x).ToList(); + } + else + { + list = documento.get_Controle().get_Documentos(); + } + IList documentos1 = list; + if (documentos1.Count > 1) + { + IList documentos2 = documentos1; + if (documentos2.Last((Documento x) => x.get_Situacao() != 7).get_Id() != this.DocumentoSelecionado.get_Id()) + { + await base.ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO ENQUANTO HOUVER ENDOSSOS EM CIMA DO MESMO.", "OK", "", false); + str2 = null; + return; + } + } + if (documento.get_Situacao() != 7) + { + if (this.SelectedDocumento.get_Tipo() != 0 || !string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str = (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice()) ? "O ENDOSSO SELECIONADO" : "A APÓLICE SELECIONADA"); + } + else + { + str = "A PROPOSTA SELECIONADA"; + } + string str3 = str; + string[] newLine = new string[] { "DESEJA REALMENTE RECUSAR ", str3, "? ", Environment.NewLine, "ESSE PROCEDIMENTO É IRREVERSÍVEL." }; + if (await base.ShowMessage(string.Concat(newLine), "SIM", "NÃO", false)) + { + str2 = null; + str2 = await base.ShowObservacaoDialog(); + if (str2 != null) + { + base.Loading(true); + await Funcoes.RecusarApolice(this.SelectedDocumento, str2, flag2); + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = string.Concat("A PROPOSTA \"", this.SelectedDocumento.get_Proposta(), "\""); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("A PROPOSTA DE ENDOSSO \"", this.SelectedDocumento.get_PropostaEndosso(), "\"") : string.Concat("O ENDOSSO \"", this.SelectedDocumento.get_Endosso(), "\"")); + } + else + { + str1 = string.Concat("A APÓLICE \"", this.SelectedDocumento.get_Apolice(), "\""); + } + string str4 = str1; + base.RegistrarAcao(string.Concat("RECUSOU ", str4), this.SelectedDocumento.get_Id(), new TipoTela?(2), string.Concat(this.GerarObs(this.SelectedDocumento), Environment.NewLine, "MOTIVO: ", str2)); + base.Loading(false); + } + } + } + else + { + await base.ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO JÁ RECUSADO.", "OK", "", false); + } + } + str2 = null; + } + + private void RemoverVendedor(long id) + { + ((this.SelectedDocumento.get_Id() == 0 || this.SelectedParcela.get_SubTipo() == 1 && !this.IsFatura ? ( + from x in this.Repasses + where x.get_Vendedor().get_Id() == id + select x).ToList() : this.Repasses.Where((VendedorParcela x) => { + if (x.get_Vendedor().get_Id() != id) + { + return false; + } + return x.get_Parcela().get_Id() == this.SelectedParcela.get_Id(); + }).ToList())).ForEach((VendedorParcela x) => this.Repasses.Remove(x)); + ((this.SelectedDocumento.get_Id() == 0 || this.SelectedParcela.get_SubTipo() == 1 && !this.IsFatura ? ( + from x in this.Pagamentos + where x.get_Vendedor().get_Id() == id + select x).ToList() : this.Pagamentos.Where((VendedorParcela x) => { + long num; + if (x.get_Vendedor().get_Id() != id) + { + return false; + } + Parcela parcela = x.get_Parcela(); + num = (parcela != null ? parcela.get_Id() : (long)0); + return num == this.SelectedParcela.get_Id(); + }).ToList())).ForEach((VendedorParcela x) => this.Pagamentos.Remove(x)); + } + + public async Task ReplicarFatura() + { + DateTime? emissao; + int num; + decimal comissao; + DateTime? vigenciaFinal; + DateTime dateTime; + DateTime? nullable1; + DateTime dateTime1; + DateTime date; + decimal valor; + decimal valorLiquidoFatura; + if (this.Parcelas != null) + { + ObservableCollection parcelas = this.Parcelas; + IOrderedEnumerable numeroParcela = + from x in parcelas + orderby x.get_NumeroParcela() + select x; + Parcela parcela = numeroParcela.LastOrDefault((Parcela x) => x.get_SubTipo() == 1); + if (parcela == null || parcela.get_NumeroParcela() != 999) + { + num = (parcela != null ? parcela.get_NumeroParcela() : 0); + int num1 = num + 1; + Parcela selectedParcela = this.SelectedParcela; + if (selectedParcela != null) + { + comissao = selectedParcela.get_Comissao(); + } + else + { + comissao = decimal.Zero; + } + decimal num2 = comissao; + ObservableCollection observableCollection = this.Parcelas; + Parcela parcela1 = observableCollection.First((Parcela x) => x.get_SubTipo() == 1); + DateTime networkTime = Funcoes.GetNetworkTime(); + Parcela parcela2 = parcela1; + if (parcela2 != null) + { + vigenciaFinal = parcela2.get_VigenciaFinal(); + } + else + { + emissao = null; + vigenciaFinal = emissao; + } + DateTime? nullable2 = vigenciaFinal; + dateTime = (nullable2.HasValue ? nullable2.GetValueOrDefault() : networkTime.Date); + DateTime dateTime2 = dateTime; + Parcela parcela3 = parcela1; + if (parcela3 != null) + { + emissao = parcela3.get_Emissao(); + if (emissao.HasValue) + { + DateTime valueOrDefault = emissao.GetValueOrDefault(); + nullable1 = new DateTime?(valueOrDefault.AddMonths(1)); + } + else + { + nullable1 = null; + } + } + else + { + emissao = null; + nullable1 = emissao; + } + nullable2 = nullable1; + dateTime1 = (nullable2.HasValue ? nullable2.GetValueOrDefault() : networkTime.Date); + DateTime dateTime3 = dateTime1; + Parcela parcela4 = parcela1; + if (parcela4 != null) + { + date = parcela4.get_Vencimento().AddMonths(1); + } + else + { + date = networkTime.Date; + } + DateTime dateTime4 = date; + DateTime dateTime5 = dateTime2.AddMonths(1); + Parcela parcela5 = parcela1; + if (parcela5 != null) + { + valor = parcela5.get_Valor(); + } + else + { + valor = decimal.Zero; + } + decimal num3 = valor; + Parcela parcela6 = parcela1; + if (parcela6 != null) + { + valorLiquidoFatura = parcela6.get_ValorLiquidoFatura(); + } + else + { + valorLiquidoFatura = decimal.Zero; + } + decimal num4 = valorLiquidoFatura; + IEnumerable vendedorParcelas = this.Repasses.Where((VendedorParcela x) => { + if (parcela1 == null) + { + return false; + } + return x.get_Parcela().get_Id() == parcela1.get_Id(); + }); + List list = Funcoes.DistinctBy(vendedorParcelas, (VendedorParcela x) => new { Id = x.get_Parcela().get_Id(), vendedor = x.get_Vendedor().get_Id(), tipovendedor = x.get_TipoVendedor().get_Id() }).ToList(); + Parcela parcela7 = new Parcela(); + parcela7.set_IdEmpresa(this.SelectedDocumento.get_Controle().get_IdEmpresa()); + parcela7.set_Documento(this.SelectedDocumento); + parcela7.set_Vencimento(dateTime4); + parcela7.set_Comissao(num2); + parcela7.set_SubTipo(1); + parcela7.set_NumeroParcela(num1); + parcela7.set_VigenciaIncial(new DateTime?(dateTime2)); + parcela7.set_VigenciaFinal(new DateTime?(dateTime5)); + parcela7.set_Valor(num3); + parcela7.set_Emissao(new DateTime?(dateTime3)); + parcela7.set_DataCriacao(new DateTime?(networkTime)); + parcela7.set_ValorLiquidoFatura(num4); + this.SelectedParcela = parcela7; + list.ForEach((VendedorParcela x) => { + decimal zero; + x.set_Id((long)0); + x.set_Parcela(this.SelectedParcela); + DateTime? nullable = null; + x.set_DataPrePagamento(nullable); + nullable = null; + x.set_DataPagamento(nullable); + VendedorParcela vendedorParcela = x; + if (x.get_Repasse() != null) + { + NegocioCorretora? negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + zero = (negocioCorretora.GetValueOrDefault() == 0 & negocioCorretora.HasValue ? x.get_Repasse().get_ValorNovo() : x.get_Repasse().get_ValorRenovacao()); + } + else + { + zero = decimal.Zero; + } + vendedorParcela.set_PorcentagemRepasse(new decimal?(zero)); + }); + this.Repasses = list; + } + else + { + await base.ShowMessage("PARCELA ESPECIAL NÃO PODE SER REPLICADA.", "OK", "", false); + return; + } + } + this.RecalculaRepasse(); + } + + public async Task>> Salvar(bool critica = false) + { + List> list; + NegocioCorretora? negocioCorretora; + NegocioCorretora? nullable; + bool id; + bool vendedor; + bool updatePremio; + bool flag2; + bool flag3; + List vendedorParcelas; + bool flag4; + Vendedor vendedor1; + Documento documento; + string str; + string str1; + bool valueOrDefault; + long? nullable1; + bool flag5; + NegocioCorretora negocioCorretora1; + string str2; + NegocioCorretora negocioCorretora2; + FormaPagamento formaPagamento; + bool vendedor2; + Negocio negocio; + object obj = null; + if (this.SelectedDocumento.get_Situacao() == 2) + { + Documento selectedDocumento = this.SelectedDocumento; + negocioCorretora = this.SelectedDocumento.get_NegocioCorretora(); + negocio = (negocioCorretora.GetValueOrDefault() == 0 & negocioCorretora.HasValue ? 2 : 1); + selectedDocumento.set_Negocio(new Negocio?(negocio)); + } + Gestor.Model.Domain.Seguros.Status status = this.SelectedDocumento.get_Status(); + if (status != null) + { + id = status.get_Id() == (long)0; + } + else + { + id = false; + } + if (id) + { + this.SelectedDocumento.set_Status(null); + } + this.ZerarValores(); + Documento selectedDocumento1 = this.SelectedDocumento; + bool isEndosso = this.IsEndosso; + List configuracaoSistemas1 = Recursos.Configuracoes; + List> keyValuePairs1 = selectedDocumento1.Validate(isEndosso, configuracaoSistemas1.Any((ConfiguracaoSistema c) => c.get_Configuracao() == 11)); + if (this.SelectedDocumento.get_Comissao() > new decimal(100)) + { + this.SelectedDocumento.set_Comissao(new decimal(100)); + } + bool id1 = this.SelectedDocumento.get_Id() == (long)0; + VendedorParcela selectedPagamento = this.SelectedPagamento; + if (selectedPagamento != null) + { + vendedor = selectedPagamento.get_Vendedor(); + } + else + { + vendedor = false; + } + if (vendedor && this.SelectedDocumento.get_Vendedores() == null) + { + Documento documento1 = this.SelectedDocumento; + List vendedors = new List() + { + this.TodosVendedores.First((Vendedor x) => { + if (!x.get_Corretora()) + { + return false; + } + return x.get_IdEmpresa() == this.SelectedDocumento.get_Controle().get_IdEmpresa(); + }) + }; + documento1.set_Vendedores(vendedors); + } + if (id1) + { + VendedorParcela vendedorParcela = this.SelectedPagamento; + if (vendedorParcela != null) + { + vendedor2 = vendedorParcela.get_Vendedor(); + } + else + { + vendedor2 = false; + } + if (vendedor2 && this.SelectedDocumento.get_Vendedores() != null) + { + List> keyValuePairs2 = keyValuePairs1; + List> keyValuePairs3 = await this.AdicionarVendedor(); + List> keyValuePairs4 = keyValuePairs2; + List> keyValuePairs5 = keyValuePairs3; + if (keyValuePairs5 == null) + { + keyValuePairs5 = new List>(); + } + keyValuePairs4.AddRange(keyValuePairs5); + keyValuePairs2 = null; + } + } + if (keyValuePairs1.Count <= 0) + { + bool tipo = this.SelectedDocumento.get_Tipo() == 0; + if (tipo) + { + tipo = !await this.VerificarVigencia(this.SelectedDocumento); + } + if (tipo) + { + if (critica) + { + keyValuePairs1.Add(new KeyValuePair("Vigencia2", "VIGENCIANAOACEITA")); + } + list = keyValuePairs1; + } + else if (this.SelectedDocumento.get_TipoEndosso().GetValueOrDefault() == 3 || this.SelectedDocumento.get_Situacao() != 3 || this.SelectedDocumento.get_Id() != 0) + { + if (this.SelectedDocumento.get_TipoEndosso().HasValue && this.SelectedDocumento.get_TipoEndosso().GetValueOrDefault() == 3) + { + this.SelectedDocumento.set_Situacao(4); + } + Documento selectedDocumento2 = this.SelectedDocumento; + base.Alterar(false); + if (!selectedDocumento2.get_FormaPagamento().HasValue) + { + Documento documento2 = selectedDocumento2; + List configuracaoSistemas2 = Recursos.Configuracoes; + formaPagamento = (configuracaoSistemas2.Any((ConfiguracaoSistema y) => y.get_Configuracao() == 21) ? 4 : 0); + documento2.set_FormaPagamento(new FormaPagamento?(formaPagamento)); + } + this.Acesso = 0; + if (selectedDocumento2.get_Id() <= (long)0 || !this.AllowEditApolice) + { + updatePremio = false; + } + else + { + if (!(this.CancelDocumento.get_PremioLiquido() != selectedDocumento2.get_PremioLiquido()) && this.CancelDocumento.get_AdicionalComiss() == selectedDocumento2.get_AdicionalComiss() && (!selectedDocumento2.get_AdicionalComiss() || !(this.CancelDocumento.get_PremioAdicional() != selectedDocumento2.get_PremioAdicional())) && !(this.CancelDocumento.get_Comissao() != selectedDocumento2.get_Comissao())) + { + negocioCorretora = this.CancelDocumento.get_NegocioCorretora(); + nullable = selectedDocumento2.get_NegocioCorretora(); + if (negocioCorretora.GetValueOrDefault() != nullable.GetValueOrDefault() | negocioCorretora.HasValue != nullable.HasValue || this.CancelDocumento.get_Diferenca() != selectedDocumento2.get_Diferenca() || this.CancelDocumento.get_Iof() != selectedDocumento2.get_Iof()) + { + goto Label1; + } + updatePremio = this.UpdatePremio; + goto Label0; + } + Label1: + updatePremio = true; + } + Label0: + bool flag6 = updatePremio; + if (selectedDocumento2.get_TipoRecebimento().GetValueOrDefault() == 2) + { + flag2 = false; + } + else + { + flag2 = (selectedDocumento2.get_Id() == 0 || this.CancelDocumento.get_NumeroParcelas() != selectedDocumento2.get_NumeroParcelas() ? true : selectedDocumento2.get_NumeroParcelas() != this.Parcelas.Count((Parcela x) => x.get_SubTipo() == 1)); + } + bool flag7 = flag2; + nullable = selectedDocumento2.get_NegocioCorretora(); + bool valueOrDefault1 = nullable.GetValueOrDefault() == 1; + if (flag7 && selectedDocumento2.get_TipoRecebimento().GetValueOrDefault() == 1) + { + this.CriarParcelas(id1); + this.Parcelas.ToList().ForEach((Parcela x) => { + x.set_Documento(selectedDocumento2); + List> keyValuePairs = keyValuePairs1; + Parcela parcela = x; + List configuracoes = Recursos.Configuracoes; + Func u003cu003e9_29911 = BaseApoliceViewModel.u003cu003ec.u003cu003e9__299_11; + if (u003cu003e9_29911 == null) + { + u003cu003e9_29911 = (ConfiguracaoSistema y) => y.get_Configuracao() == 9; + BaseApoliceViewModel.u003cu003ec.u003cu003e9__299_11 = u003cu003e9_29911; + } + bool flag = configuracoes.Any(u003cu003e9_29911); + List configuracaoSistemas = Recursos.Configuracoes; + Func u003cu003e9_29912 = BaseApoliceViewModel.u003cu003ec.u003cu003e9__299_12; + if (u003cu003e9_29912 == null) + { + u003cu003e9_29912 = (ConfiguracaoSistema y) => y.get_Configuracao() == 11; + BaseApoliceViewModel.u003cu003ec.u003cu003e9__299_12 = u003cu003e9_29912; + } + bool flag1 = configuracaoSistemas.Any(u003cu003e9_29912); + bool editandoParcela = this.EditandoParcela; + List configuracoes1 = Recursos.Configuracoes; + Func u003cu003e9_29913 = BaseApoliceViewModel.u003cu003ec.u003cu003e9__299_13; + if (u003cu003e9_29913 == null) + { + u003cu003e9_29913 = (ConfiguracaoSistema r) => r.get_Configuracao() == 16; + BaseApoliceViewModel.u003cu003ec.u003cu003e9__299_13 = u003cu003e9_29913; + } + keyValuePairs.AddRange(parcela.Validate(flag, flag1, editandoParcela, configuracoes1.Any(u003cu003e9_29913))); + }); + if (keyValuePairs1.Count > 0) + { + base.Alterar(true); + list = keyValuePairs1.Distinct>().ToList>(); + return list; + } + } + if (this.Parcelas == null || this.Parcelas.Count == 0) + { + this.Pagamentos = new ObservableCollection(); + } + if (flag6 && !flag7) + { + this.AtualizaValores(valueOrDefault1); + } + if (this.SelectedDocumento.get_Situacao() == 5 && this.SelectedDocumento.get_Controle().get_Documentos() != null && this.SelectedDocumento.get_Controle().get_Documentos().Count > 0) + { + IList documentos = this.SelectedDocumento.get_Controle().get_Documentos(); + foreach (Documento documento3 in documentos.Where((Documento x) => { + if (x.get_Tipo() == 0) + { + return false; + } + return !x.get_Excluido(); + })) + { + if (documento3.get_Situacao() == 3) + { + continue; + } + documento3.set_SituacaoAnterior(new TipoSeguro?(documento3.get_Situacao())); + documento3.set_Situacao(5); + await this.Servico.Save(documento3, false, false); + } + } + if (this.SelectedDocumento.get_Id() != 0 && this.SelectedDocumento.get_Tipo() == 0 && this.SelectedDocumento.get_Controle().get_Documentos() != null && this.SelectedDocumento.get_Controle().get_Documentos().Count > 0) + { + IList documentos1 = this.SelectedDocumento.get_Controle().get_Documentos(); + if (documentos1.Where((Documento x) => { + if (x.get_Tipo() == 0) + { + return false; + } + return !x.get_Excluido(); + }).Any((Documento x) => { + if (x.get_Apolice() != this.SelectedDocumento.get_Apolice()) + { + return true; + } + return x.get_Proposta() != this.SelectedDocumento.get_Proposta(); + })) + { + IList documentos2 = this.SelectedDocumento.get_Controle().get_Documentos(); + foreach (Documento documento4 in documentos2.Where((Documento x) => { + if (x.get_Tipo() == 0) + { + return false; + } + return !x.get_Excluido(); + })) + { + documento4.set_Apolice(this.SelectedDocumento.get_Apolice()); + documento4.set_Proposta(this.SelectedDocumento.get_Proposta()); + await this.Servico.Save(documento4, false, false); + base.ToggleSnackBar("NUMERO DA PROPOSTA/APOLICE ATUALIZADOS NO ENDOSSO", true); + } + } + } + if (this.Renovar) + { + nullable = this.CancelDocumento.get_NegocioCorretora(); + if (!nullable.HasValue) + { + Documento cancelDocumento = this.CancelDocumento; + negocioCorretora2 = (!this.CancelDocumento.get_Negocio().HasValue || this.CancelDocumento.get_Negocio().GetValueOrDefault() != 1 ? 0 : 1); + cancelDocumento.set_NegocioCorretora(new NegocioCorretora?(negocioCorretora2)); + } + this.CancelDocumento.set_Situacao(5); + IList documentos3 = this.CancelDocumento.get_Controle().get_Documentos(); + IEnumerable documentos4 = documentos3.Where((Documento d) => { + if (d.get_Tipo() != 1) + { + return false; + } + if (d.get_Situacao() == 1 || d.get_Situacao() == 2) + { + return true; + } + return d.get_Situacao() == 4; + }); + foreach (Documento documento5 in documentos4) + { + documento5.set_Situacao(5); + await this.Servico.Save(documento5, false, false); + } + this.Servico.Sucesso = true; + await this.Servico.Save(this.CancelDocumento, false, false); + if (!this.Servico.Sucesso) + { + await base.ShowMessage("NÃO FOI POSSÍVEL ALTERAR O STATUS DO DOCUMENTO RENOVADO, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO.", "OK", "", false); + } + str2 = (string.IsNullOrEmpty(this.CancelDocumento.get_Apolice()) ? string.Concat("A PROPOSTA \"", this.CancelDocumento.get_Proposta(), "\"") : string.Concat("A APÓLICE \"", this.CancelDocumento.get_Apolice(), "\"")); + string str3 = str2; + base.RegistrarAcao(string.Concat("RENOVOU ", str3), this.CancelDocumento.get_Id(), new TipoTela?(2), this.GerarObs(this.CancelDocumento)); + } + if (selectedDocumento2.get_TipoEndosso().HasValue && selectedDocumento2.get_TipoEndosso().GetValueOrDefault() == 4 && this.SelectedDocumento.get_Vigencia2().HasValue) + { + ApoliceServico servico = this.Servico; + long num = this.SelectedDocumento.get_Controle().get_Id(); + DateTime? vigencia2 = this.SelectedDocumento.get_Vigencia2(); + if (!await servico.Prorrogar(num, vigencia2.Value)) + { + await base.ShowMessage("NÃO FOI POSSÍVEL ALTERAR A VIGÊNCIA FINAL DA APÓLICE, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO.", "OK", "", false); + } + } + if (selectedDocumento2.get_TipoEndosso().HasValue && selectedDocumento2.get_TipoEndosso().GetValueOrDefault() == 3) + { + if (!await this.Servico.Reabilitar(this.SelectedDocumento.get_Controle().get_Id())) + { + await base.ShowMessage("NÃO FOI POSSÍVEL ALTERAR O STATUS DA APÓLICE, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO.", "OK", "", false); + } + } + if (selectedDocumento2.get_TipoEndosso().HasValue && selectedDocumento2.get_TipoEndosso().GetValueOrDefault() == 2) + { + IList documentos5 = this.CancelDocumento.get_Controle().get_Documentos(); + Documento documento6 = documentos5.FirstOrDefault((Documento x) => x.get_Tipo() == 0); + documento6.set_Situacao(3); + IList documentos6 = this.CancelDocumento.get_Controle().get_Documentos(); + IEnumerable tipo1 = + from x in documentos6 + where x.get_Tipo() == 1 + select x; + foreach (Documento documento7 in tipo1) + { + documento7.set_Situacao(3); + await this.Servico.Save(documento7, false, false); + } + nullable = documento6.get_NegocioCorretora(); + if (!nullable.HasValue) + { + Documento documento8 = documento6; + negocioCorretora1 = (!documento6.get_Negocio().HasValue || documento6.get_Negocio().GetValueOrDefault() != 1 ? 0 : 1); + documento8.set_NegocioCorretora(new NegocioCorretora?(negocioCorretora1)); + } + selectedDocumento2.set_Situacao(3); + this.Servico.Sucesso = true; + await this.Servico.Save(documento6, false, false); + if (!this.Servico.Sucesso) + { + await base.ShowMessage("NÃO FOI POSSÍVEL ALTERAR O STATUS DO DOCUMENTO CANCELADO, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO.", "OK", "", false); + } + tipo = id1; + if (tipo) + { + tipo = await base.ShowMessage("DESEJA BAIXAR AS PARCELAS PENDENTES ABAIXO DESSE DOCUMENTO?", "SIM", "NÃO", false); + } + if (tipo) + { + bool flag8 = true; + foreach (Documento documento9 in documento6.get_Controle().get_Documentos()) + { + tipo = await this.Servico.BaixarParcelasCancelamento(documento9, false); + flag8 = tipo & flag8; + } + if (!flag8) + { + await base.ShowMessage("NÃO FOI POSSÍVEL AS PARCELAS DO DOCUMENTO CANCELADO, POR FAVOR VERIFIQUE APÓS O PROCEDIMENTO SER CONCLUÍDO.", "OK", "", false); + } + } + string str4 = string.Concat("A APÓLICE \"", documento6.get_Apolice(), "\""); + base.RegistrarAcao(string.Concat("CANCELOU ", str4), documento6.get_Id(), new TipoTela?(2), this.GerarObs(documento6)); + documento6 = null; + } + if (this.Parcelas != null) + { + Documento documento10 = selectedDocumento2; + ObservableCollection parcelas = this.Parcelas; + documento10.set_Parcelas(new ObservableCollection( + from x in parcelas + where x.get_SubTipo() == 1 + select x)); + } + if (!string.IsNullOrWhiteSpace(this.Anotacoes)) + { + Documento documento11 = selectedDocumento2; + object[] nome = new object[] { Recursos.Usuario.get_Nome(), Recursos.Usuario.get_Id(), Funcoes.GetNetworkTime(), Environment.NewLine, this.Anotacoes, Environment.NewLine, Environment.NewLine, selectedDocumento2.get_Observacao() }; + documento11.set_Observacao(string.Format("{0}, ID: {1}, {2:g}{3}{4}{5}{6}{7}", nome)); + } + Documento documentoSelecionado = this.DocumentoSelecionado; + if (documentoSelecionado != null) + { + documentoSelecionado.get_Situacao(); + flag3 = true; + } + else + { + flag3 = false; + } + if (flag3 && this.DocumentoSelecionado.get_Situacao() == 7 && this.DocumentoSelecionado.get_Situacao() != selectedDocumento2.get_Situacao()) + { + ObservableCollection observableCollection = selectedDocumento2.get_Parcelas(); + if (observableCollection != null) + { + flag5 = ( + from x in observableCollection + where x.get_DataRecebimento().HasValue + select x).Count() >= 1; + } + else + { + flag5 = false; + } + if (flag5) + { + await base.ShowMessage("O DOCUMENTO TEM PARCELAS BAIXADAS DEVIDO A RECUSA. CASO NECESSÁRIO, REALIZE A EXCLUSÃO DAS BAIXAS MANUALMENTE.", "OK", "", false); + base.Alterar(true); + list = null; + return list; + } + } + this.Servico.Sucesso = true; + if (selectedDocumento2.get_Id() == 0) + { + selectedDocumento2.set_DataCriacao(new DateTime?(Funcoes.GetNetworkTime())); + selectedDocumento2.set_UsuarioCriacao(Recursos.Usuario); + } + selectedDocumento2.set_SituacaoAnterior(new TipoSeguro?(selectedDocumento2.get_Situacao())); + Documento documento12 = await this.Servico.Save(selectedDocumento2, flag6, flag7); + Documento documento13 = documento12; + ObservableCollection pagamentos = this.Pagamentos; + if (pagamentos != null) + { + vendedorParcelas = pagamentos.Where((VendedorParcela p) => { + if (documento13.get_TipoRecebimento().GetValueOrDefault() != 1 || p.get_Repasse() == null || p.get_Repasse().get_Base().GetValueOrDefault() != 1 && p.get_Repasse().get_Base().GetValueOrDefault() != 4 && p.get_Repasse().get_Base().GetValueOrDefault() != 5) + { + return false; + } + return !p.get_DataPagamento().HasValue; + }).ToList(); + } + else + { + vendedorParcelas = null; + } + List vendedorParcelas1 = vendedorParcelas; + if (vendedorParcelas1 != null && vendedorParcelas1.Count > 0) + { + List vendedorParcelas2 = new List(); + if (vendedorParcelas1 != null) + { + vendedorParcelas1.ForEach((VendedorParcela p) => { + DateTime? dataPrePagamento; + DateTime? emissao; + BaseRepasse? @base = p.get_Repasse().get_Base(); + if (@base.HasValue) + { + switch (@base.GetValueOrDefault()) + { + case 1: + { + dataPrePagamento = p.get_DataPrePagamento(); + DateTime vigencia1 = documento13.get_Vigencia1(); + if ((dataPrePagamento.HasValue ? dataPrePagamento.GetValueOrDefault() == vigencia1 : false)) + { + return; + } + p.set_DataPrePagamento(new DateTime?(documento13.get_Vigencia1())); + vendedorParcelas2.Add(p); + return; + } + case 2: + case 3: + { + break; + } + case 4: + { + dataPrePagamento = p.get_DataPrePagamento(); + emissao = documento13.get_Emissao(); + if ((dataPrePagamento.HasValue == emissao.HasValue ? (dataPrePagamento.HasValue ? dataPrePagamento.GetValueOrDefault() == emissao.GetValueOrDefault() : true) : false)) + { + return; + } + p.set_DataPrePagamento(documento13.get_Emissao()); + vendedorParcelas2.Add(p); + return; + } + case 5: + { + emissao = p.get_DataPrePagamento(); + dataPrePagamento = documento13.get_Remessa(); + if ((emissao.HasValue == dataPrePagamento.HasValue ? (emissao.HasValue ? emissao.GetValueOrDefault() == dataPrePagamento.GetValueOrDefault() : true) : false)) + { + return; + } + p.set_DataPrePagamento(documento13.get_Remessa()); + vendedorParcelas2.Add(p); + break; + } + default: + { + return; + } + } + } + }); + } + if (vendedorParcelas2.Count > 0) + { + await (new Gestor.Application.Servicos.ParcelaServico()).SaveRange(vendedorParcelas2.ToList()); + } + } + if (this.Servico.Sucesso) + { + Documento documentoSelecionado1 = this.DocumentoSelecionado; + if (documentoSelecionado1 != null) + { + documentoSelecionado1.get_Situacao(); + flag4 = true; + } + else + { + flag4 = false; + } + if (flag4 && this.DocumentoSelecionado.get_Situacao() == 7 && selectedDocumento2.get_Situacao() != this.DocumentoSelecionado.get_Situacao()) + { + Action acessaTela = Gestor.Application.Actions.Actions.AcessaTela; + if (acessaTela != null) + { + acessaTela(21, ""); + } + else + { + } + } + this.SelectedDocumento = await this.Servico.BuscarApoliceAsync(documento13.get_Id(), false, false); + this.SelectedDocumento.Initialize(); + await this.CarregarParcelas(this.SelectedDocumento); + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + this.SelectedParcela = this.Parcelas.FirstOrDefault(); + Documento selectedDocumento3 = this.SelectedDocumento; + List repasses = this.Repasses; + VendedorParcela vendedorParcela1 = repasses.FirstOrDefault((VendedorParcela x) => x.get_TipoVendedor().get_Id() == (long)1); + if (vendedorParcela1 != null) + { + vendedor1 = vendedorParcela1.get_Vendedor(); + } + else + { + vendedor1 = null; + } + selectedDocumento3.set_VendedorPrincipal(vendedor1); + bool renovar = this.Renovar; + documento = (renovar ? this.DocumentoRenovado : ConsultaViewModel.DocumentoSelecionado); + ConsultaViewModel.DocumentoRenovado = documento; + this.NovaApolice = false; + this.Renovar = false; + if (id1) + { + this.AllowEditApolice = true; + base.IsEnabledEdit = true; + base.IsEnabledEditEndosso = true; + if (this.Invoke) + { + ConsultaViewModel.DocumentoSelecionado = this.SelectedDocumento; + } + if (this.Invoke) + { + Action recarregarDocumentos = Gestor.Application.Actions.Actions.RecarregarDocumentos; + if (recarregarDocumentos != null) + { + recarregarDocumentos(this.SelectedDocumento); + } + else + { + } + } + if (this.Invoke) + { + Action updateDocumento = Gestor.Application.Actions.Actions.UpdateDocumento; + if (updateDocumento != null) + { + updateDocumento(this.SelectedDocumento); + } + else + { + } + } + } + else if (this.Invoke) + { + long num1 = this.SelectedDocumento.get_Id(); + Documento documentoSelecionado2 = ConsultaViewModel.DocumentoSelecionado; + if (documentoSelecionado2 != null) + { + nullable1 = new long?(documentoSelecionado2.get_Id()); + } + else + { + nullable1 = null; + } + long? nullable2 = nullable1; + if (num1 != nullable2.GetValueOrDefault() | !nullable2.HasValue) + { + ConsultaViewModel.DocumentoSelecionado = this.SelectedDocumento; + } + } + if (this.Parcelas.Count == 0) + { + this.AllowEditVendedor = false; + } + base.AllowEditParcela = true; + base.ToggleSnackBar("DOCUMENTO SALVO COM SUCESSO", true); + Action enableMainMenu = Gestor.Application.Actions.Actions.EnableMainMenu; + if (enableMainMenu != null) + { + enableMainMenu(true); + } + else + { + } + Action enableMenu = Gestor.Application.Actions.Actions.EnableMenu; + if (enableMenu != null) + { + enableMenu(true); + } + else + { + } + if (renovar) + { + if (await base.ShowMessage("DESEJA MANTER OS DADOS DO PERFIL DA APÓLICE ANTERIOR?", "SIM", "NÃO", false)) + { + List perfils = await this.PerfilServico.BuscarPerfis(this.CancelDocumento.get_Controle().get_Id()); + int num2 = 0; + try + { + foreach (Perfil perfil in perfils.ToList()) + { + Perfil perfil1 = new Perfil(); + perfil1.set_Id((long)0); + perfil1.set_AntiFurto(perfil.get_AntiFurto()); + perfil1.set_CepCirculacao(Gestor.Model.Helper.ValidationHelper.FormataCep(perfil.get_CepCirculacao())); + perfil1.set_CepPernoite(Gestor.Model.Helper.ValidationHelper.FormataCep(perfil.get_CepPernoite())); + perfil1.set_Cliente(perfil.get_Cliente()); + Controle controle = new Controle(); + controle.set_AssistenciaId(perfil.get_Controle().get_AssistenciaId()); + controle.set_Cliente(perfil.get_Controle().get_Cliente()); + controle.set_Documentos(perfil.get_Controle().get_Documentos()); + controle.set_Id(this.SelectedDocumento.get_Controle().get_Id()); + controle.set_IdEmpresa(perfil.get_Controle().get_IdEmpresa()); + controle.set_Item(perfil.get_Controle().get_Item()); + controle.set_Produto(perfil.get_Controle().get_Produto()); + controle.set_Ramo(perfil.get_Controle().get_Ramo()); + controle.set_Seguradora(perfil.get_Controle().get_Seguradora()); + controle.set_SeguradoraAnterior(perfil.get_Controle().get_SeguradoraAnterior()); + perfil1.set_Controle(controle); + perfil1.set_Cpf(perfil.get_Cpf()); + perfil1.set_DistanciaResidenciaTrabalho(perfil.get_DistanciaResidenciaTrabalho()); + perfil1.set_EstadoCivil(perfil.get_EstadoCivil()); + perfil1.set_EstenderCobertura(perfil.get_EstenderCobertura()); + perfil1.set_GaragemEstudo(perfil.get_GaragemEstudo()); + perfil1.set_GaragemResidencia(perfil.get_GaragemResidencia()); + perfil1.set_GaragemTrabalho(perfil.get_GaragemTrabalho()); + perfil1.set_Habilitacao(perfil.get_Habilitacao()); + perfil1.set_Isencao(perfil.get_Isencao()); + perfil1.set_KmMensal(perfil.get_KmMensal()); + perfil1.set_Nascimento(perfil.get_Nascimento()); + perfil1.set_Nome(perfil.get_Nome()); + perfil1.set_Ocupacao(perfil.get_Ocupacao()); + perfil1.set_Relacao(perfil.get_Relacao()); + perfil1.set_SeguroVida(perfil.get_SeguroVida()); + perfil1.set_Sexo(perfil.get_Sexo()); + perfil1.set_TempoHabilitacao(perfil.get_TempoHabilitacao()); + perfil1.set_TipoResidencia(perfil.get_TipoResidencia()); + perfil1.set_UsoDependentes(perfil.get_UsoDependentes()); + perfil1.set_UsoProfissional(perfil.get_UsoProfissional()); + perfil1.set_VeiculoResidencia(perfil.get_VeiculoResidencia()); + await this.PerfilServico.Save(perfil1); + } + } + catch (Exception exception) + { + obj = exception; + num2 = 1; + } + if (num2 == 1) + { + Exception exception1 = (Exception)obj; + await base.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.", "OK", "", false); + } + obj = null; + } + } + this.CancelDocumento = (Documento)this.SelectedDocumento.Clone(); + BaseApoliceViewModel baseApoliceViewModel = this; + str = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? "EDITAR FATURAS" : "EDITAR PARCELAS"); + baseApoliceViewModel.EditarParcelasLabel = str; + base.EnableFields = false; + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + string str5 = (id1 ? "INCLUIU" : "ALTEROU"); + if (this.SelectedDocumento.get_Tipo() == 0 && string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = string.Concat("A PROPOSTA \"", this.SelectedDocumento.get_Proposta(), "\""); + } + else if (this.SelectedDocumento.get_Tipo() != 0 || string.IsNullOrEmpty(this.SelectedDocumento.get_Apolice())) + { + str1 = (string.IsNullOrEmpty(this.SelectedDocumento.get_Endosso()) ? string.Concat("A PROPOSTA DE ENDOSSO \"", this.SelectedDocumento.get_PropostaEndosso(), "\"") : string.Concat("O ENDOSSO \"", this.SelectedDocumento.get_Endosso(), "\"")); + } + else + { + str1 = string.Concat("A APÓLICE \"", this.SelectedDocumento.get_Apolice(), "\""); + } + string str6 = str1; + base.RegistrarAcao(string.Concat(str5, " ", str6), this.SelectedDocumento.get_Id(), new TipoTela?(2), this.GerarObs(this.SelectedDocumento)); + if (renovar) + { + valueOrDefault = true; + } + else if (!this.IsEndosso) + { + valueOrDefault = false; + } + else + { + TipoEndosso? tipoEndosso = this.SelectedDocumento.get_TipoEndosso(); + valueOrDefault = tipoEndosso.GetValueOrDefault() != 2; + } + if (valueOrDefault & id1) + { + Action action = Gestor.Application.Actions.Actions.AcessaTela; + if (action != null) + { + action(3, (renovar ? "Renovação" : "Endosso")); + } + else + { + } + list = null; + } + else if (this.SelectedDocumento.get_TipoEndosso().GetValueOrDefault() != 2) + { + tipo = (!this.Invoke ? true : !id1); + if (!tipo) + { + tipo = !await base.ShowMessage("DESEJA INCLUIR O ITEM AGORA?", "SIM", "NÃO", false); + } + if (!tipo) + { + Action acessaTela1 = Gestor.Application.Actions.Actions.AcessaTela; + if (acessaTela1 != null) + { + acessaTela1(3, ""); + } + else + { + } + list = null; + } + else + { + list = null; + } + } + else + { + list = null; + } + } + else + { + base.Alterar(true); + list = null; + } + } + else + { + await base.ShowMessage("EM DOCUMENTOS CANCELADOS SÓ É POSSIVEL INCLUIR ENDOSSO DE REABILITAÇÃO.", "OK", "", false); + base.Alterar(true); + list = null; + } + } + else + { + list = keyValuePairs1; + } + return list; + } + + public async Task>> SalvarParcelas(int tipo) + { + List> keyValuePairs; + decimal num; + int num1; + bool flag; + if (this.SelectedParcela.get_Documento() == null) + { + this.SelectedParcela.set_Documento(this.SelectedDocumento); + } + this.SelectedParcela.get_Documento().set_Parcelas(this.Parcelas); + if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 && this.SelectedParcela.get_SubTipo() == 1 && this.SelectedParcela.get_Comissao() == decimal.Zero) + { + this.SelectedParcela.set_Comissao(this.SelectedDocumento.get_Comissao()); + } + Parcela selectedParcela = this.SelectedParcela; + List configuracoes = Recursos.Configuracoes; + bool flag1 = configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 9); + List configuracaoSistemas = Recursos.Configuracoes; + bool flag2 = configuracaoSistemas.Any((ConfiguracaoSistema y) => y.get_Configuracao() == 11); + bool editandoParcela = this.EditandoParcela; + List configuracoes1 = Recursos.Configuracoes; + List> keyValuePairs1 = selectedParcela.Validate(flag1, flag2, editandoParcela, configuracoes1.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 16)); + keyValuePairs1.AddRange(this.ValidaParcelaEspecial(tipo)); + num = (this.SelectedParcela.get_ValorExtrato() == decimal.Zero ? this.SelectedParcela.get_ValorLiquidoFatura() : this.SelectedParcela.get_ValorExtrato()); + decimal num2 = num; + num1 = (num2 > decimal.Zero ? num2.CompareTo(this.SelectedParcela.get_ValorComissao()) : this.SelectedParcela.get_ValorComissao().CompareTo(num2)); + int num3 = num1; + flag = (keyValuePairs1.Count != 1 || 2 != this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() ? false : num3 < 0); + bool flag3 = flag; + if (flag3) + { + flag3 = await base.ShowMessage("VALOR RECEBIMENTO MAIOR QUE VALOR PARCELA, CONTINUAR?", "SIM", "NÃO", false); + } + if (flag3) + { + keyValuePairs1.Clear(); + } + if (keyValuePairs1.Count <= 0) + { + this.SelectedParcela.set_Baixando(false); + List configuracaoSistemas1 = Recursos.Configuracoes; + if (!configuracaoSistemas1.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 5) && (this.SelectedParcela.get_Iss() > decimal.Zero || this.SelectedParcela.get_Irr() > decimal.Zero || this.SelectedParcela.get_Outros() > decimal.Zero || this.SelectedParcela.get_Desconto() > decimal.Zero)) + { + this.SelectedParcela.set_Iss(decimal.Zero); + this.SelectedParcela.set_Irr(decimal.Zero); + this.SelectedParcela.set_Outros(decimal.Zero); + this.SelectedParcela.set_Desconto(decimal.Zero); + this.SelectedParcela.set_ValorComDesconto(this.SelectedParcela.get_ValorComissao()); + } + switch (tipo) + { + case 1: + { + await this.AlterarVencimento(); + break; + } + case 2: + { + await this.BaixarComissao(); + break; + } + case 3: + case 4: + { + await this.AdicionarParcelaEspecial(); + break; + } + } + keyValuePairs = null; + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + public async void Seleciona(Documento documento) + { + base.Loading(true); + await base.PermissaoTela(2); + await base.PermissaoTela(5); + if (documento == null || (object)documento != (object)this.SelectedDocumento) + { + await this.SelecionaDocumento(documento); + } + Action redimencionar = Gestor.Application.Actions.Actions.Redimencionar; + if (redimencionar != null) + { + redimencionar(this.Invoke); + } + else + { + } + base.Loading(false); + } + + public async Task SelecionaDocumento(Documento documento) + { + long? nullable; + base.Loading(true); + base.IsEnabled = false; + await this.BuscarVendedores(false); + List estipulantes = await (new BaseServico()).BuscarEstipulantes(); + BaseApoliceViewModel list = this; + IEnumerable estipulantes1 = estipulantes.Where((Estipulante x) => { + if (documento == null) + { + return x.get_IdEmpresa() == Recursos.Usuario.get_IdEmpresa(); + } + if (x.get_IdEmpresa() != documento.get_Controle().get_IdEmpresa()) + { + return false; + } + return x.get_Ativo(); + }); + list.Estipulantes = ( + from x in estipulantes1 + orderby x.get_Nome() + select x).ToList(); + this.SelectedDocumento = null; + this.PreLoad(); + if (documento != null) + { + await this.WorkOnSelectedDocumento(documento); + if (this.Invoke) + { + long id = this.SelectedDocumento.get_Id(); + Documento documentoSelecionado = ConsultaViewModel.DocumentoSelecionado; + if (documentoSelecionado != null) + { + nullable = new long?(documentoSelecionado.get_Id()); + } + else + { + nullable = null; + } + long? nullable1 = nullable; + if (id != nullable1.GetValueOrDefault() | !nullable1.HasValue) + { + ConsultaViewModel.DocumentoSelecionado = this.SelectedDocumento; + } + } + if (this.Acesso == 1 && this.ParcelaSelecionada != 0) + { + await this.SelecionaParcela(this.Parcelas.FirstOrDefault((Parcela x) => x.get_Id() == this.ParcelaSelecionada)); + } + if (this.Invoke) + { + this.Loaded = true; + } + base.IsEnabled = true; + base.Loading(false); + } + else + { + base.EnableFields = false; + base.Loading(false); + } + } + + public async Task SelecionaParcela(Parcela parcela) + { + bool flag; + bool flag1; + this.SelectedParcela = parcela; + if (parcela != null && parcela.get_Id() != 0 && this.SelectedDocumento != null) + { + if (this.Repasses == null) + { + await this.CarregaRepasse(this.SelectedDocumento.get_Id()); + } + List list = ( + from x in this.Repasses + where x.get_Parcela().get_Id() == parcela.get_Id() + select x).ToList(); + if (this.IsFatura || parcela.get_SubTipo() != 1) + { + BaseApoliceViewModel baseApoliceViewModel = this; + flag = (parcela.get_DataRecebimento().HasValue ? false : list.All((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != parcela.get_Id()) + { + return false; + } + return !x.get_DataPagamento().HasValue; + })); + baseApoliceViewModel.AllowEditVendedor = flag; + } + if (!this.IsFatura && parcela.get_SubTipo() == 1) + { + BaseApoliceViewModel baseApoliceViewModel1 = this; + if (parcela.get_NumeroParcela() != 1 || parcela.get_DataRecebimento().HasValue) + { + flag1 = false; + } + else + { + List vendedorParcelas = list; + flag1 = vendedorParcelas.All((VendedorParcela x) => { + if (x.get_Parcela().get_SubTipo() != 1) + { + return false; + } + return !x.get_DataPagamento().HasValue; + }); + } + baseApoliceViewModel1.AllowEditVendedor = flag1; + } + BaseApoliceViewModel observableCollection = this; + List vendedorParcelas1 = list; + observableCollection.Pagamentos = new ObservableCollection( + from x in vendedorParcelas1 + orderby x.get_TipoVendedor().get_Id() + select x); + } + } + + public void SelecionaPrimeiraParcela() + { + this.SelectedParcela = this.SelectedParcela ?? this.Parcelas.FirstOrDefault(); + } + + public async Task SelecionarParcelaBaixa() + { + bool flag; + decimal num; + decimal num1; + Parcela parcela; + if (this.SelectedParcela == null || this.SelectedDocumento == null) + { + flag = false; + } + else if (this.SelectedParcela.get_SubTipo() != 1 && !this.SelectedParcela.get_DataRecebimento().HasValue) + { + Parcela selectedParcela = this.SelectedParcela; + decimal premioLiquido = this.SelectedDocumento.get_PremioLiquido(); + num1 = (this.SelectedDocumento.get_NumeroParcelas() > decimal.Zero ? this.SelectedDocumento.get_NumeroParcelas() : decimal.One); + selectedParcela.set_ValorLiquidoFatura(premioLiquido / num1); + this.SelectedParcela.set_Baixando(true); + flag = true; + } + else if (this.IsFatura && !this.SelectedParcela.get_DataRecebimento().HasValue) + { + this.SelectedParcela.set_Baixando(true); + flag = true; + } + else if (this.Parcelas == null || !this.Parcelas.Any()) + { + flag = false; + } + else + { + ObservableCollection parcelas = this.Parcelas; + IOrderedEnumerable numeroParcela = + from x in parcelas + orderby x.get_NumeroParcela() + select x; + parcela = numeroParcela.FirstOrDefault((Parcela x) => { + if (x.get_DataRecebimento().HasValue) + { + return false; + } + return x.get_SubTipo() == 1; + }); + if (parcela != null && !this.IsFatura && this.SelectedDocumento.get_NumeroParcelas() > decimal.Zero) + { + Parcela parcela1 = parcela; + num = (this.SelectedDocumento.get_AdicionalComiss() ? (this.SelectedDocumento.get_PremioLiquido() + this.SelectedDocumento.get_PremioAdicional()) / this.SelectedDocumento.get_NumeroParcelas() : this.SelectedDocumento.get_PremioLiquido() / this.SelectedDocumento.get_NumeroParcelas()); + parcela1.set_ValorLiquidoFatura(num); + } + BaseApoliceViewModel baseApoliceViewModel = this; + Parcela selectedParcela1 = parcela; + if (selectedParcela1 == null) + { + selectedParcela1 = this.SelectedParcela; + } + baseApoliceViewModel.SelectedParcela = selectedParcela1; + if (parcela == null) + { + await base.ShowMessage("NÃO HÁ MAIS NENHUMA PARCELA A SER BAIXADA", "OK", "", false); + } + if (parcela != null) + { + this.SelectedParcela.set_Baixando(true); + } + flag = parcela != null; + } + parcela = null; + return flag; + } + + public void SelecionarVendedor() + { + VendedorParcela vendedorParcela; + ObservableCollection pagamentos = this.Pagamentos; + if (pagamentos != null) + { + vendedorParcela = pagamentos.FirstOrDefault(); + } + else + { + vendedorParcela = null; + } + this.SelectedPagamento = vendedorParcela; + } + + public void ToggleSeguradoraAnterior(TipoSeguro situacao) + { + if (situacao != 2) + { + this.IsRenovacaoVisibility = Visibility.Collapsed; + return; + } + this.IsRenovacaoVisibility = Visibility.Visible; + } + + private List> ValidaParcelaEspecial(int tipo) + { + List> keyValuePairs = new List>(); + if (tipo == 4 && this.SelectedParcela.get_SubTipo() == 1) + { + keyValuePairs.Add(new KeyValuePair("SubTipo|TIPO", "A PARCELA ESPECIAL NÃO PODE SER DO TIPO PARCELA NORMAL")); + } + return keyValuePairs; + } + + public List> Validate(VendedorParcela pagamento) + { + long? nullable; + bool count; + List> keyValuePairs = new List>(); + if (pagamento == null || this.SelectedDocumento == null) + { + keyValuePairs.Add(new KeyValuePair("pagamento|PAGAMENTO", "ERRO AO INSERIR VENDEDOR.")); + return keyValuePairs; + } + if (pagamento.get_TipoVendedor() == null || pagamento.get_Vendedor() == null) + { + return keyValuePairs; + } + if (this.Repasses == null) + { + this.Repasses = new List(); + } + if (this.Repasses.Count > 0) + { + if (this.Repasses.All((VendedorParcela x) => x.get_Parcela() == null)) + { + if (this.SelectedDocumento.get_Id() > (long)0) + { + ObservableCollection parcelas = this.Parcelas; + if (parcelas != null) + { + count = parcelas.Count > 0; + } + else + { + count = false; + } + if (count) + { + keyValuePairs.Add(new KeyValuePair("|PARCELA", "PARCELA DEVE SER SELECIONADA PARA A INCLUSÃO DO VENDEDOR.")); + return keyValuePairs; + } + } + if (this.SelectedDocumento.get_Tipo() != 1) + { + goto Label1; + } + keyValuePairs.Add(new KeyValuePair("|PARCELA", "PARCELA DEVE SER SELECIONADA PARA A INCLUSÃO DO VENDEDOR.")); + return keyValuePairs; + } + Label1: + IEnumerable vendedorParcelas = this.Repasses.Where((VendedorParcela x) => { + if (x.get_Parcela().get_SubTipo() != 1) + { + return false; + } + decimal? porcentagemRepasse = x.get_PorcentagemRepasse(); + if ((porcentagemRepasse.GetValueOrDefault() == 100) & porcentagemRepasse.HasValue) + { + return false; + } + return pagamento.get_Repasse().get_Forma().GetValueOrDefault() == 1; + }); + decimal num = vendedorParcelas.Sum((VendedorParcela x) => x.get_ValorRepasse().GetValueOrDefault()) + pagamento.get_ValorRepasse().GetValueOrDefault(); + decimal num1 = ((this.SelectedDocumento.get_AdicionalComiss() ? this.SelectedDocumento.get_PremioLiquido() + this.SelectedDocumento.get_PremioAdicional() : this.SelectedDocumento.get_PremioLiquido()) * this.SelectedDocumento.get_Comissao()) * new decimal(1, 0, 0, false, 2); + if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 15) && Math.Abs(num) > (Math.Abs(num1) + this.Tolerancia)) + { + keyValuePairs.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 (this.Repasses.Where((VendedorParcela vendedorParcela) => { + if (vendedorParcela.get_Repasse() == null) + { + return false; + } + return vendedorParcela.get_Repasse().get_Tipo().GetValueOrDefault() != 3; + }).Any((VendedorParcela x) => { + if (x.get_TipoVendedor().get_Id() != pagamento.get_TipoVendedor().get_Id() || x.get_Vendedor().get_Corretora()) + { + return false; + } + return x.get_Parcela().get_SubTipo() == 1; + })) + { + keyValuePairs.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", string.Concat("JÁ EXISTE UM VENDEDOR DO TIPO ", pagamento.get_TipoVendedor().get_Descricao(), " ADICIONADO AO DOCUMENTO."))); + } + if (this.Repasses.Any((VendedorParcela x) => { + if (x.get_Vendedor().get_Id() != pagamento.get_Vendedor().get_Id()) + { + return false; + } + return x.get_Parcela().get_SubTipo() == 1; + })) + { + keyValuePairs.Add(new KeyValuePair("Nome|VENDEDOR", string.Concat("VENDEDOR ", pagamento.get_Vendedor().get_Nome(), " JÁ ADICIONADO AO DOCUMENTO."))); + } + } + long id = pagamento.get_Vendedor().get_Id(); + Gestor.Model.Domain.Seguros.Repasse repasse = pagamento.get_Repasse(); + if (repasse != null) + { + nullable = new long?(repasse.get_Vendedor().get_Id()); + } + else + { + nullable = null; + } + long? nullable1 = nullable; + if (id != nullable1.GetValueOrDefault() | !nullable1.HasValue) + { + keyValuePairs.Add(new KeyValuePair("ValorRepasse|VALOR DO REPASSE", "PERCENTUAL DE REPASSE DEVE SER SELECIONADO")); + } + return keyValuePairs; + } + + public List> ValidateEspecial(VendedorParcela pagamento) + { + decimal? nullable2; + List> keyValuePairs = new List>(); + if (this.SelectedParcela == null) + { + keyValuePairs.Add(new KeyValuePair("SelectedParcela|PARCELA", "PARCELA DEVE SER SELECIONADA PARA A INCLUSÃO DO VENDEDOR.")); + return keyValuePairs; + } + if (this.Repasses == null) + { + this.Repasses = new List(); + } + decimal? nullable3 = ( + from x in this.Repasses + where x.get_Parcela().get_Id() == pagamento.get_Parcela().get_Id() + select x).Sum((VendedorParcela x) => x.get_ValorRepasse()); + decimal? valorRepasse = pagamento.get_ValorRepasse(); + if (nullable3.HasValue & valorRepasse.HasValue) + { + nullable2 = new decimal?(nullable3.GetValueOrDefault() + valorRepasse.GetValueOrDefault()); + } + else + { + nullable2 = null; + } + decimal? nullable4 = nullable2; + decimal valor = this.SelectedParcela.get_Valor(); + decimal num = (this.SelectedParcela.get_DataRecebimento().HasValue ? this.SelectedParcela.get_ValorComDesconto() : (valor * this.SelectedParcela.get_Comissao()) * new decimal(1, 0, 0, false, 2)); + if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => x.get_Configuracao() != 15) && nullable4.HasValue && Math.Abs(nullable4.Value) > (Math.Abs(num) + this.Tolerancia)) + { + keyValuePairs.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.get_Parcela() == null) + { + if (this.Repasses.Any((VendedorParcela x) => { + if (x.get_TipoVendedor().get_Id() != pagamento.get_TipoVendedor().get_Id()) + { + return false; + } + return !x.get_Vendedor().get_Corretora(); + })) + { + keyValuePairs.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", string.Concat("JÁ EXISTE UM VENDEDOR DO TIPO ", pagamento.get_TipoVendedor().get_Descricao(), " ADICIONADO AO DOCUMENTO."))); + } + if (this.Repasses.Any((VendedorParcela x) => x.get_Vendedor().get_Id() == pagamento.get_Vendedor().get_Id())) + { + keyValuePairs.Add(new KeyValuePair("Nome|VENDEDOR", string.Concat("VENDEDOR ", pagamento.get_Vendedor().get_Nome(), " JÁ ADICIONADO AO DOCUMENTO"))); + } + return keyValuePairs; + } + if (pagamento.get_Parcela().get_SubTipo() == 1) + { + if (this.Repasses.Any((VendedorParcela x) => { + long? nullable; + long id = x.get_TipoVendedor().get_Id(); + TipoVendedor tipoVendedor = pagamento.get_TipoVendedor(); + if (tipoVendedor != null) + { + nullable = new long?(tipoVendedor.get_Id()); + } + else + { + nullable = null; + } + long? nullable1 = nullable; + if (!(id == nullable1.GetValueOrDefault() & nullable1.HasValue) || x.get_Vendedor().get_Corretora()) + { + return false; + } + return x.get_Parcela().get_Id() == pagamento.get_Parcela().get_Id(); + })) + { + keyValuePairs.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", string.Concat("JÁ EXISTE UM VENDEDOR DO TIPO ", pagamento.get_TipoVendedor().get_Descricao(), " ADICIONADO AO DOCUMENTO."))); + } + if (this.Repasses.Any((VendedorParcela x) => { + if (x.get_Vendedor().get_Id() != pagamento.get_Vendedor().get_Id()) + { + return false; + } + return x.get_Parcela().get_Id() == pagamento.get_Parcela().get_Id(); + })) + { + keyValuePairs.Add(new KeyValuePair("Nome|VENDEDOR", string.Concat("VENDEDOR ", pagamento.get_Vendedor().get_Nome(), " JÁ ADICIONADO AO DOCUMENTO"))); + } + return keyValuePairs; + } + if (this.Repasses.Any((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != pagamento.get_Parcela().get_Id() || x.get_TipoVendedor().get_Id() != pagamento.get_TipoVendedor().get_Id()) + { + return false; + } + return !x.get_Vendedor().get_Corretora(); + })) + { + keyValuePairs.Add(new KeyValuePair("TipoVendedor|TIPO VENDEDOR", string.Concat("JÁ EXISTE UM VENDEDOR DO TIPO ", pagamento.get_TipoVendedor().get_Descricao(), " ADICIONADO A PARCELA."))); + } + if (this.Repasses.Any((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != pagamento.get_Parcela().get_Id()) + { + return false; + } + return x.get_Vendedor().get_Id() == pagamento.get_Vendedor().get_Id(); + })) + { + keyValuePairs.Add(new KeyValuePair("Nome|VENDEDOR", string.Concat("VENDEDOR ", pagamento.get_Vendedor().get_Nome(), " JÁ ADICIONADO A PARCELA"))); + } + return keyValuePairs; + } + + public List VendedorCoCorretagem(bool coCorretagem = false) + { + List vendedors; + if (coCorretagem) + { + List list = this.Vendedores.Where((Vendedor vendedor) => { + List repassesVendedores = this.RepassesVendedores; + if (repassesVendedores == null) + { + return false; + } + return repassesVendedores.FindAll((Gestor.Model.Domain.Seguros.Repasse repasse) => repasse.get_Vendedor().get_Id() == vendedor.get_Id()).Any((Gestor.Model.Domain.Seguros.Repasse x) => x.get_Tipo().GetValueOrDefault() == 3); + }).ToList(); + vendedors = list; + this.Vendedores = list; + return vendedors; + } + List list1 = Recursos.Vendedores.Where((Vendedor vendedor) => { + if (!vendedor.get_Ativo() || vendedor.get_Corretora()) + { + return false; + } + return vendedor.get_IdEmpresa() == Recursos.Usuario.get_IdEmpresa(); + }).OrderBy((Vendedor v) => v.get_Nome()).ToList(); + vendedors = list1; + this.Vendedores = list1; + return vendedors; + } + + public bool VerificaCoCorretagem() + { + List repasses = this.Repasses; + if (repasses == null) + { + return false; + } + return repasses.Any((VendedorParcela x) => x.get_CoCorretagem()); + } + + public async Task VerificarVigencia(Documento documento) + { + bool flag; + string str; + if (documento.get_Vigencia2().HasValue) + { + DateTime? vigencia2 = documento.get_Vigencia2(); + TimeSpan timeSpan = DateTime.Parse(vigencia2.ToString()) - documento.get_Vigencia1(); + if (timeSpan.Days > 366) + { + str = "VIGÊNCIA FINAL MAIOR QUE 365 DIAS.\nDESEJA CONTINUAR?"; + } + else + { + str = (timeSpan.Days < 365 ? "VIGÊNCIA FINAL MENOR QUE 365 DIAS.\nDESEJA CONTINUAR?" : ""); + } + string str1 = str; + if (str1 != "") + { + flag = await base.ShowMessage(str1, "SIM", "NÃO", false); + } + else + { + flag = true; + } + } + else + { + flag = true; + } + return flag; + } + + private async Task WorkOnSelectedDocumento(Documento value) + { + decimal? nullable; + bool flag; + bool flag1; + bool seguradora; + List list; + decimal? tolerancia; + bool flag2; + bool flag3; + bool valueOrDefault; + string str; + NegocioCorretora negocioCorretora; + Documento documento; + BaseApoliceViewModel baseApoliceViewModel = this; + flag = (value == null ? true : value.get_Id() == (long)0); + baseApoliceViewModel.IsEnabledEdit = flag; + BaseApoliceViewModel baseApoliceViewModel1 = this; + flag1 = (value == null ? true : value.get_Id() == (long)0); + baseApoliceViewModel1.IsEnabledEditEndosso = flag1; + if (value != null && value.get_Id() != 0) + { + if (!this.Situacao.All((TipoSeguro x) => x != value.get_Situacao())) + { + this.IsEnableSituacao = true; + } + else + { + List tipoSeguros = new List() + { + 1, + 2, + 5, + value.get_Situacao() + }; + this.Situacao = new ObservableCollection(tipoSeguros); + } + Controle controle = value.get_Controle(); + if (controle != null) + { + seguradora = controle.get_Seguradora(); + } + else + { + seguradora = false; + } + if (seguradora) + { + list = Recursos.Seguradoras.Where((Seguradora x) => { + if (x.get_Ativo()) + { + return true; + } + return x.get_Id() == value.get_Controle().get_Seguradora().get_Id(); + }).ToList(); + } + else + { + List seguradoras = Recursos.Seguradoras; + list = ( + from x in seguradoras + where x.get_Ativo() + select x).ToList(); + } + this.Seguradoras = list; + this.SeguradorasAnteriores = Recursos.Seguradoras; + this.SelectedDocumento = await this.Servico.BuscarApoliceAsync(value.get_Id(), false, false); + if (!this.SelectedDocumento.get_NegocioCorretora().HasValue) + { + Documento selectedDocumento = this.SelectedDocumento; + negocioCorretora = (this.SelectedDocumento.get_Situacao() != 2 || !this.SelectedDocumento.get_Negocio().HasValue || this.SelectedDocumento.get_Negocio().GetValueOrDefault() != 1 ? 0 : 1); + selectedDocumento.set_NegocioCorretora(new NegocioCorretora?(negocioCorretora)); + base.OnPropertyChanged("SelectedDocumento"); + } + BaseApoliceViewModel valueOrDefault1 = this; + Controle controle1 = this.SelectedDocumento.get_Controle(); + if (controle1 != null) + { + Seguradora seguradora1 = controle1.get_Seguradora(); + if (seguradora1 != null) + { + tolerancia = seguradora1.get_Tolerancia(); + } + else + { + nullable = null; + tolerancia = nullable; + } + } + else + { + nullable = null; + tolerancia = nullable; + } + nullable = tolerancia; + valueOrDefault1.Tolerancia = nullable.GetValueOrDefault(new decimal(2)); + List produtos = Recursos.Produtos.Where((Produto x) => { + if (x.get_Ativo()) + { + return true; + } + if (this.SelectedDocumento.get_Controle().get_Produto() == null) + { + return false; + } + return x.get_Id() == this.SelectedDocumento.get_Controle().get_Produto().get_Id(); + }).ToList(); + this.Produtos = produtos; + if (this.Invoke) + { + ConsultaViewModel.DocumentoSelecionado = this.SelectedDocumento; + } + documento = (Documento)this.SelectedDocumento.Clone(); + await this.CarregarParcelas(documento); + await this.CarregaRepasse(documento.get_Id()); + this.SelectedDocumento.Initialize(); + this.Initialized = true; + if (this.Parcelas.Count == 0) + { + this.AllowEditVendedor = false; + } + BaseApoliceViewModel baseApoliceViewModel2 = this; + ObservableCollection parcelas = this.Parcelas; + IEnumerable subTipo = + from x in parcelas + where x.get_SubTipo() == 1 + select x; + if (!subTipo.All((Parcela x) => !x.get_DataRecebimento().HasValue)) + { + flag2 = false; + } + else + { + List repasses = this.Repasses; + IEnumerable vendedorParcelas = + from x in repasses + where x.get_Parcela().get_SubTipo() == 1 + select x; + flag2 = vendedorParcelas.All((VendedorParcela x) => !x.get_DataPagamento().HasValue); + } + baseApoliceViewModel2.AllowEditApolice = flag2; + BaseApoliceViewModel baseApoliceViewModel3 = this; + if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2) + { + flag3 = true; + } + else + { + List repasses1 = this.Repasses; + IEnumerable vendedorParcelas1 = repasses1.Where((VendedorParcela x) => { + if (x.get_Repasse() == null) + { + return false; + } + return x.get_Repasse().get_Base().GetValueOrDefault() == 4; + }); + flag3 = vendedorParcelas1.All((VendedorParcela x) => !x.get_DataPagamento().HasValue); + } + baseApoliceViewModel3.AllowEditEmissao = flag3; + this.CalculaComissao(this.SelectedDocumento, this.Parcelas); + this.IsEndosso = this.SelectedDocumento.get_Tipo() != 0; + BaseApoliceViewModel baseApoliceViewModel4 = this; + if (!this.SelectedDocumento.get_TipoEndosso().HasValue) + { + valueOrDefault = true; + } + else if (this.SelectedDocumento.get_TipoEndosso().GetValueOrDefault() == 2) + { + valueOrDefault = false; + } + else + { + TipoEndosso? tipoEndosso = this.SelectedDocumento.get_TipoEndosso(); + valueOrDefault = tipoEndosso.GetValueOrDefault() != 3; + } + baseApoliceViewModel4.EnableAlterarSituacao = valueOrDefault; + BaseApoliceViewModel baseApoliceViewModel5 = this; + str = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2 ? "EDITAR FATURAS" : "EDITAR PARCELAS"); + baseApoliceViewModel5.EditarParcelasLabel = str; + base.AllowEditParcela = true; + this.CancelDocumento = (Documento)this.SelectedDocumento.Clone(); + } + documento = null; + } + + private void WorkOnSelectedParcela(Parcela value) + { + bool? nullable; + string str; + Visibility visibility; + int? nullable1; + bool? nullable2; + if (value == null || value.get_Id() == 0 || this.SelectedDocumento == null) + { + return; + } + bool flag = this.Repasses.Any((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != this.SelectedParcela.get_Id()) + { + return false; + } + return x.get_DataPagamento().HasValue; + }); + if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 2) + { + List repasses = this.Repasses; + if (repasses != null) + { + nullable2 = new bool?(repasses.Where((VendedorParcela x) => { + if (x.get_Parcela().get_Id() != this.SelectedParcela.get_Id() || x.get_Repasse() == null) + { + return false; + } + return x.get_Repasse().get_Base().GetValueOrDefault() == 4; + }).All((VendedorParcela x) => !x.get_DataPagamento().HasValue)); + } + else + { + nullable = null; + nullable2 = nullable; + } + nullable = nullable2; + this.AllowEditEmissao = nullable.Value; + } + if (value.get_SubTipo() != 1 || this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 1) + { + this.BaixarParcelaVisibility = (!value.get_DataRecebimento().HasValue ? Visibility.Visible : Visibility.Collapsed); + this.VisibilityExcluirParcela = (flag ? Visibility.Collapsed : Visibility.Visible); + if (value.get_DataRecebimento().HasValue) + { + str = "EXCLUIR BAIXA"; + } + else + { + str = (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 ? "EXCLUIR PARCELA" : "EXCLUIR FATURA"); + } + this.ExcluirParcelaLabel = str; + } + else + { + this.BaixarParcelaVisibility = (this.Parcelas.Any((Parcela x) => { + if (x.get_DataRecebimento().HasValue) + { + return false; + } + return x.get_SubTipo() == 1; + }) ? Visibility.Visible : Visibility.Collapsed); + Parcela parcela = ( + from x in this.Parcelas + orderby x.get_NumeroParcela() + select x).LastOrDefault((Parcela x) => { + if (!x.get_DataRecebimento().HasValue || x.get_SubTipo() != 1) + { + return false; + } + if (x.get_ValorComissao() != decimal.Zero) + { + return true; + } + return x.get_ValorRealizado() != decimal.Zero; + }); + if (flag) + { + visibility = Visibility.Collapsed; + } + else + { + if (!value.get_DataRecebimento().HasValue || parcela != null) + { + if (parcela != null) + { + nullable1 = new int?(parcela.get_NumeroParcela()); + } + else + { + nullable1 = null; + } + int? nullable3 = nullable1; + int numeroParcela = value.get_NumeroParcela(); + if (nullable3.GetValueOrDefault() <= numeroParcela & nullable3.HasValue) + { + goto Label1; + } + visibility = Visibility.Collapsed; + goto Label0; + } + Label1: + visibility = Visibility.Visible; + } + Label0: + this.VisibilityExcluirParcela = visibility; + this.ExcluirParcelaLabel = "EXCLUIR BAIXA"; + } + this.VisibilityReplicarFatura = (this.IsFatura ? Visibility.Visible : Visibility.Collapsed); + } + + private void WorkOnSelectedTipo(bool value) + { + this.Assinada = (value ? "PROPOSTA DE ENDOSSO ASSINADA" : "PROPOSTA ASSINADA"); + this.Conferida = (value ? "ENDOSSO CONFERIDO" : "APÓLICE CONFERIDA"); + this.Transmissao = (value ? "TRANSMISSÃO DA PROPOSTA DE ENDOSSO" : "TRANSMISSÃO DA PROPOSTA"); + this.Emissao = (value ? "EMISSÃO DO ENDOSSO" : "EMISSÃO DA APÓLICE"); + } + + private void ZeraComissao() + { + this.Gerada = decimal.Zero; + this.Recebida = decimal.Zero; + this.Pendente = decimal.Zero; + this.Repasse = decimal.Zero; + this.ComissOriginal = decimal.Zero; + } + + private void ZerarValores() + { + if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() != 2) + { + return; + } + this.SelectedDocumento.set_PremioLiquido(decimal.Zero); + this.SelectedDocumento.set_PremioAdicional(decimal.Zero); + this.SelectedDocumento.set_PremioAdicional(decimal.Zero); + this.SelectedDocumento.set_Iof(decimal.Zero); + this.SelectedDocumento.set_Diferenca(decimal.Zero); + this.SelectedDocumento.set_NumeroParcelas(decimal.Zero); + } + } +} \ No newline at end of file -- cgit v1.2.3