using Assinador.Infrastructure.Helpers; using ClosedXML.Excel; using Gestor.Application.Actions; using Gestor.Application.Helpers; using Gestor.Application.Model; 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.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Configuracoes; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Threading; namespace Gestor.Application.ViewModels.Seguros { public class ConsultaViewModel : BaseSegurosViewModel { private readonly ApoliceServico _apoliceServico; private readonly ParcelaServico _parcelaServico; private readonly ItemServico _itemServico; private readonly VendedorServico _vendedorServico; public bool UpdatingScroll; public static Parcela ParcelaSelecionada; public static Item ItemSelecionado; private static Documento _documentoSelecionado; private bool _apelido; private Visibility _semDocumentos = Visibility.Collapsed; private Cliente _selectedCliente = new Cliente(); private bool _carregando; private bool _isLoading; private Visibility _visibilityParcelasVendedores; private ObservableCollection _apolices = new ObservableCollection(); private ObservableCollection _endossos = new ObservableCollection(); private Documento _selectedEndosso = new Documento(); private string _parcelasLabel = "PARCELAS"; private Documento _selectedControle = new Documento(); private bool _isFatura; private bool _isEnabledParcelaItem = true; private Item _selectedItem = new Item(); private ObservableCollection _itens = new ObservableCollection(); private Parcela _selectedParcela = new Parcela(); private ObservableCollection _parcelas = new ObservableCollection(); private Visibility _isVisibleRadioEndosso = Visibility.Collapsed; private Visibility _isVisibleEndosso = Visibility.Collapsed; private Visibility _isVisibleApolice; private string _pendenciaApolice = ""; private Visibility _isVisiblePendenciaApolice = Visibility.Collapsed; private decimal _gerada; private decimal _recebida; private decimal _pendente; private bool _isLoadingParcelas = true; private bool _isLoadingItens = true; private int _filterItens; private int _filterDocumento; private Visibility _manutencaoItemVisibility; private Visibility _recusaVisibility; private Visibility _renovarVisibility; private Visibility _endossarVisibility; private Visibility _trocarClienteVisibility; private Visibility _tarefasVisibility; private Visibility _comissaoVisibility; private Visibility _comissaoValorVisibility; private Visibility _mostrarItensVisibility = Visibility.Collapsed; private Visibility _mostrarSinistroVisibility; private ObservableCollection _telefones = new ObservableCollection(); public bool Apelido { get { return this._apelido; } set { this._apelido = value; base.OnPropertyChanged("Apelido"); } } public ObservableCollection Apolices { get { return this._apolices; } set { this._apolices = value; base.OnPropertyChanged("Apolices"); } } public bool Carregando { get { return this._carregando; } set { this._carregando = value; this.SemDocumentos = (value || this.Apolices != null && this.Apolices.Count != 0 ? Visibility.Collapsed : Visibility.Visible); } } public Visibility ComissaoValorVisibility { get { return this._comissaoValorVisibility; } set { this._comissaoValorVisibility = (!base.Restricao(14) ? value : Visibility.Collapsed); base.OnPropertyChanged("ComissaoValorVisibility"); } } public Visibility ComissaoVisibility { get { return this._comissaoVisibility; } set { this._comissaoVisibility = (!base.Restricao(95) ? value : Visibility.Collapsed); base.OnPropertyChanged("ComissaoVisibility"); } } public static Documento DocumentoRenovado { get; set; } public static Documento DocumentoSelecionado { get { return ConsultaViewModel._documentoSelecionado; } set { ConsultaViewModel._documentoSelecionado = value; Action enableItens = Gestor.Application.Actions.Actions.EnableItens; if (enableItens != null) { enableItens((value == null ? false : value.get_Id() > (long)0)); } else { } Action enableDocumento = Gestor.Application.Actions.Actions.EnableDocumento; if (enableDocumento == null) { return; } enableDocumento((value == null ? false : value.get_Id() > (long)0)); } } public Visibility EndossarVisibility { get { return this._endossarVisibility; } set { this._endossarVisibility = (!base.Restricao(33) ? value : Visibility.Collapsed); base.OnPropertyChanged("EndossarVisibility"); } } public ObservableCollection Endossos { get { return this._endossos; } set { this._endossos = value; base.OnPropertyChanged("Endossos"); } } public int FilterDocumento { get { return this._filterDocumento; } set { this._filterDocumento = value; Action updateRadioApolice = Gestor.Application.Actions.Actions.UpdateRadioApolice; if (updateRadioApolice != null) { updateRadioApolice(this._filterDocumento); } else { } base.OnPropertyChanged("FilterDocumento"); } } public int FilterItens { get { return this._filterItens; } set { this._filterItens = value; ConsultaViewModel.FiltrarItens = value; base.OnPropertyChanged("FilterItens"); } } public static int FiltrarItens { get; set; } public decimal Gerada { get { return this._gerada; } set { this._gerada = value; base.OnPropertyChanged("Gerada"); } } public bool IsEnabledParcelaItem { get { return this._isEnabledParcelaItem; } set { this._isEnabledParcelaItem = value; base.OnPropertyChanged("IsEnabledParcelaItem"); } } public bool IsFatura { get { return this._isFatura; } set { if (!value) { value = this.ComissaoValorVisibility == Visibility.Collapsed; } this._isFatura = value; base.OnPropertyChanged("IsFatura"); } } public bool IsLoading { get { return this._isLoading; } set { this._isLoading = value; base.OnPropertyChanged("IsLoading"); } } public bool IsLoadingItens { get { return this._isLoadingItens; } set { this._isLoadingItens = value; base.OnPropertyChanged("IsLoadingItens"); } } public bool IsLoadingParcelas { get { return this._isLoadingParcelas; } set { this._isLoadingParcelas = value; base.OnPropertyChanged("IsLoadingParcelas"); } } public Visibility IsVisibleApolice { get { return this._isVisibleApolice; } set { this._isVisibleApolice = value; base.OnPropertyChanged("IsVisibleApolice"); } } public Visibility IsVisibleEndosso { get { return this._isVisibleEndosso; } set { this._isVisibleEndosso = value; base.OnPropertyChanged("IsVisibleEndosso"); } } public Visibility IsVisiblePendenciaApolice { get { return this._isVisiblePendenciaApolice; } set { this._isVisiblePendenciaApolice = value; base.OnPropertyChanged("IsVisiblePendenciaApolice"); } } public Visibility IsVisibleRadioEndosso { get { return this._isVisibleRadioEndosso; } set { this._isVisibleRadioEndosso = value; base.OnPropertyChanged("IsVisibleRadioEndosso"); } } public ObservableCollection Itens { get { return this._itens; } set { this._itens = value; base.OnPropertyChanged("Itens"); } } public bool ItensRevelados { get; set; } public Visibility ManutencaoItemVisibility { get { return this._manutencaoItemVisibility; } set { this._manutencaoItemVisibility = (!base.Restricao(22) ? value : Visibility.Collapsed); base.OnPropertyChanged("ManutencaoItemVisibility"); } } public Visibility MostrarItensVisibility { get { return this._mostrarItensVisibility; } set { this._mostrarItensVisibility = value; base.OnPropertyChanged("MostrarItensVisibility"); } } public Visibility MostrarSinistroVisibility { get { return this._mostrarSinistroVisibility; } set { this._mostrarSinistroVisibility = value; base.OnPropertyChanged("MostrarSinistroVisibility"); } } public ObservableCollection Parcelas { get { return this._parcelas; } set { this._parcelas = value; base.OnPropertyChanged("Parcelas"); } } public string ParcelasLabel { get { return this._parcelasLabel; } set { this._parcelasLabel = value; base.OnPropertyChanged("ParcelasLabel"); } } public string PendenciaApolice { get { return this._pendenciaApolice; } set { this._pendenciaApolice = value; this.IsVisiblePendenciaApolice = (string.IsNullOrEmpty(this._pendenciaApolice) ? Visibility.Collapsed : Visibility.Visible); base.OnPropertyChanged("PendenciaApolice"); } } public decimal Pendente { get { return this._pendente; } set { this._pendente = value; base.OnPropertyChanged("Pendente"); } } public bool Pesquisando { get; set; } public bool Recarregando { get; set; } 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 Visibility RenovarVisibility { get { return this._renovarVisibility; } set { this._renovarVisibility = (!base.Restricao(17) ? value : Visibility.Collapsed); base.OnPropertyChanged("RenovarVisibility"); } } public Cliente SelectedCliente { get { return this._selectedCliente; } set { this._selectedCliente = value; base.OnPropertyChanged("SelectedCliente"); } } public Documento SelectedControle { get { return this._selectedControle; } set { bool id; bool flag; Visibility visibility; string apolice; this._selectedControle = value; if (value == null || value.get_Id() <= (long)0) { id = false; } else { Usuario usuario = Recursos.Usuario; if (usuario != null) { id = usuario.get_Id() > (long)0; } else { id = false; } } base.EnableButtons = id; 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())); this.WorkOnSelectedDocumento(value); 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; this.ItensRevelados = false; this.MostrarItensVisibility = Visibility.Collapsed; this.MostrarSinistroVisibility = Visibility.Visible; base.OnPropertyChanged("SelectedControle"); return; } visibility = Visibility.Collapsed; this.RecusaVisibility = visibility; this.ItensRevelados = false; this.MostrarItensVisibility = Visibility.Collapsed; this.MostrarSinistroVisibility = Visibility.Visible; base.OnPropertyChanged("SelectedControle"); return; } visibility = Visibility.Visible; this.RecusaVisibility = visibility; this.ItensRevelados = false; this.MostrarItensVisibility = Visibility.Collapsed; this.MostrarSinistroVisibility = Visibility.Visible; base.OnPropertyChanged("SelectedControle"); } } public Documento SelectedEndosso { get { return this._selectedEndosso; } set { this._selectedEndosso = value; this.WorkOnSelectedDocumento(value); base.OnPropertyChanged("SelectedEndosso"); } } public Item SelectedItem { get { return this._selectedItem; } set { this._selectedItem = value; ConsultaViewModel.WorkOnSelectedItem(value); base.OnPropertyChanged("SelectedItem"); } } public Parcela SelectedParcela { get { return this._selectedParcela; } set { this._selectedParcela = value; base.OnPropertyChanged("SelectedParcela"); } } public Visibility SemDocumentos { get { return this._semDocumentos; } set { this._semDocumentos = value; base.OnPropertyChanged("SemDocumentos"); } } public Visibility TarefasVisibility { get { return this._tarefasVisibility; } set { this._tarefasVisibility = (base.Permissao(38) ? value : Visibility.Collapsed); base.OnPropertyChanged("TarefasVisibility"); } } public ObservableCollection Telefones { get { return this._telefones; } set { this._telefones = value; base.OnPropertyChanged("Telefones"); } } public Visibility TrocarClienteVisibility { get { return this._trocarClienteVisibility; } set { this._trocarClienteVisibility = (!base.Restricao(21) ? value : Visibility.Collapsed); base.OnPropertyChanged("TrocarClienteVisibility"); } } public Visibility VisibilityParcelasVendedores { get { return this._visibilityParcelasVendedores; } set { this._visibilityParcelasVendedores = value; base.OnPropertyChanged("VisibilityParcelasVendedores"); } } public ConsultaViewModel() { this._apoliceServico = new ApoliceServico(); this._parcelaServico = new ParcelaServico(); this._vendedorServico = new VendedorServico(); this._itemServico = new ItemServico(); this.Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 6); this.SemDocumentos = Visibility.Visible; base.EnableButtons = false; if (MainViewModel.ClienteSelecionado != null && MainViewModel.ClienteSelecionado.get_Id() > (long)0) { this.SelecionarCliente(MainViewModel.ClienteSelecionado); } } public async Task AbrirDetalhes() { Documento selectedControle = this.SelectedControle; if (this.FilterDocumento == 1) { Documento selectedEndosso = this.SelectedEndosso; if (selectedEndosso == null) { selectedEndosso = this.SelectedControle; } selectedControle = selectedEndosso; } Documento documento = selectedControle; List vendedorParcelas = await this._vendedorServico.BuscaRepasse(selectedControle.get_Id()); documento.set_Pagamentos(vendedorParcelas); documento = null; documento = selectedControle; ObservableCollection observableCollection = await this._parcelaServico.BuscarParcelasAsync(selectedControle.get_Id()); documento.set_Parcelas(observableCollection); documento = null; Documento documento1 = selectedControle; selectedControle = null; return documento1; } public async Task AbrirDetalhesParcela() { Parcela selectedParcela = this.SelectedParcela; List vendedorParcelas = await this._vendedorServico.BuscaRepasseParcela(selectedParcela.get_Id()); selectedParcela.set_Vendedores(new ObservableCollection(vendedorParcelas)); Parcela parcela = selectedParcela; selectedParcela = null; return parcela; } private void CalculaComissao(Documento documento, ObservableCollection parcelas) { 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); } public void CarregaDocumentos(int type) { this.IsVisibleApolice = Visibility.Collapsed; this.IsVisibleEndosso = Visibility.Collapsed; if (type != 1) { this.IsVisibleApolice = Visibility.Visible; return; } this.IsVisibleEndosso = Visibility.Visible; } public async Task CarregaItens(int type, Documento documento) { this.FilterItens = 0; switch (type) { case 0: { this.Itens = await this._itemServico.BuscarItens(documento.get_Controle().get_Id(), 0); break; } case 1: { this.FilterItens = 1; this.Itens = await this._itemServico.BuscarItens(documento.get_Id(), 2); break; } case 2: { this.FilterItens = 2; Documento selectedEndosso = this.SelectedEndosso; if (selectedEndosso == null) { selectedEndosso = documento; } documento = selectedEndosso; this.Itens = await this._itemServico.BuscarItens(documento.get_Id(), 2); break; } case 3: { this.FilterItens = 3; this.Itens = await this._itemServico.BuscarItens(documento.get_Controle().get_Id(), 1); break; } } } private void Clear() { this.Apolices = null; this.Parcelas = null; this.Itens = null; } public async Task CreateLink(Documento documento) { string str; string descricao; if (documento == null || this.SelectedCliente == null) { str = ""; } else { this.Telefones = new ObservableCollection((IEnumerable)await (new ClienteServico()).BuscarTelefonesAsync(this.SelectedCliente.get_Id())); if (this.Itens == null) { descricao = ""; } else if (this.Itens.Count > 1) { descricao = "APÓLICE COLETIVA"; } else { Item item = this.Itens.FirstOrDefault(); if (item != null) { descricao = item.get_Descricao(); } else { descricao = null; } } str = await base.CreateLinkAssistencia(documento, descricao, true); } return str; } public async Task EditarParcelas() { await base.ShowEditarParcelasDialog(ConsultaViewModel.DocumentoSelecionado); await this.SelecionaParcelas(ConsultaViewModel.DocumentoSelecionado); } public async Task GerarExcel(int type) { ObservableCollection observableCollection; string str1; ConsultaViewModel.u003cu003ec__DisplayClass212_0 variable; string str2; string str3; if (this.SelectedControle != null) { base.Loading(true); bool typeFromProgID = Type.GetTypeFromProgID("Excel.Application") != null; str2 = "ATIVOS"; switch (type) { case 1: { str2 = "DA APÓLICE"; observableCollection = await this._itemServico.BuscarItems(this.SelectedControle.get_Id(), 2, true); break; } case 2: { Documento selectedEndosso = this.SelectedEndosso; if (selectedEndosso == null) { selectedEndosso = this.SelectedControle; } Documento documento = selectedEndosso; str2 = (this.SelectedEndosso == null ? "DA APÓLICE" : "DO ENDOSSO"); observableCollection = await this._itemServico.BuscarItems(documento.get_Id(), 2, true); break; } case 3: { str2 = "INATIVOS"; observableCollection = await this._itemServico.BuscarItems(this.SelectedControle.get_Controle().get_Id(), 1, true); break; } default: { observableCollection = await this._itemServico.BuscarItems(this.SelectedControle.get_Controle().get_Id(), 0, true); break; } } if (observableCollection == null || observableCollection.Count == 0) { base.Loading(false); await base.ShowMessage("NÃO HÁ ITENS PARA EXIBIR A RELAÇÃO", "OK", "", false); } else { List relacaoItens = new List(); observableCollection.ToList().ForEach((Item x) => { DateTime? nullable; StatusSinistro? nullable1; decimal? nullable2; DateTime? dataSinistro; string numero; StatusSinistro? statusSinistro; string itemSinistrado; decimal? nullable3; DateTime? dataLiquidacao; DateTime? dataReclamacao; string motivo; string descricao; string str = ""; if (x.get_Coberturas().Count() > 0) { x.get_Coberturas().ToList().ForEach((Cobertura c) => str = string.Concat(str, string.Format("Cobertura: {0} | Premio: {1} | Franquia: {2} | LMI: {3}\n", new object[] { c.get_Observacao(), c.get_Premio(), c.get_Franquia(), c.get_Lmi() }))); } RelacaoItens relacaoIten = new RelacaoItens() { Nome = this.SelectedCliente.get_Nome(), Documento = this.SelectedCliente.get_Documento(), Apolice = this.SelectedControle.get_Apolice(), VigenciaInicial = this.SelectedControle.get_Vigencia1(), VigenciaFinal = this.SelectedControle.get_Vigencia2(), Ordem = x.get_Ordem(), Sinistrado = (x.get_Sinistrado() ? "SIM" : "NÃO") }; ControleSinistro controleSinistro = x.get_Sinistros().FirstOrDefault(); if (controleSinistro != null) { dataSinistro = controleSinistro.get_DataSinistro(); } else { nullable = null; dataSinistro = nullable; } relacaoIten.DataSinistro = dataSinistro; ControleSinistro controleSinistro1 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro1 != null) { Sinistro sinistro = controleSinistro1.get_Sinistros().FirstOrDefault(); if (sinistro != null) { numero = sinistro.get_Numero(); } else { numero = null; } } else { numero = null; } relacaoIten.NumSinistro = numero; ControleSinistro controleSinistro2 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro2 != null) { Sinistro sinistro1 = controleSinistro2.get_Sinistros().FirstOrDefault(); if (sinistro1 != null) { statusSinistro = sinistro1.get_StatusSinistro(); } else { nullable1 = null; statusSinistro = nullable1; } } else { nullable1 = null; statusSinistro = nullable1; } relacaoIten.StatusSinistro = statusSinistro; ControleSinistro controleSinistro3 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro3 != null) { Sinistro sinistro2 = controleSinistro3.get_Sinistros().FirstOrDefault(); if (sinistro2 != null) { itemSinistrado = sinistro2.get_ItemSinistrado(); } else { itemSinistrado = null; } } else { itemSinistrado = null; } relacaoIten.ItemSinistrado = itemSinistrado; ControleSinistro controleSinistro4 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro4 != null) { Sinistro sinistro3 = controleSinistro4.get_Sinistros().FirstOrDefault(); if (sinistro3 != null) { nullable3 = new decimal?(sinistro3.get_Valor()); } else { nullable2 = null; nullable3 = nullable2; } } else { nullable2 = null; nullable3 = nullable2; } relacaoIten.Valor = nullable3; ControleSinistro controleSinistro5 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro5 != null) { Sinistro sinistro4 = controleSinistro5.get_Sinistros().FirstOrDefault(); if (sinistro4 != null) { dataLiquidacao = sinistro4.get_DataLiquidacao(); } else { nullable = null; dataLiquidacao = nullable; } } else { nullable = null; dataLiquidacao = nullable; } relacaoIten.DataLiq = dataLiquidacao; ControleSinistro controleSinistro6 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro6 != null) { Sinistro sinistro5 = controleSinistro6.get_Sinistros().FirstOrDefault(); if (sinistro5 != null) { dataReclamacao = sinistro5.get_DataReclamacao(); } else { nullable = null; dataReclamacao = nullable; } } else { nullable = null; dataReclamacao = nullable; } relacaoIten.DataRec = dataReclamacao; ControleSinistro controleSinistro7 = x.get_Sinistros().FirstOrDefault(); if (controleSinistro7 != null) { Sinistro sinistro6 = controleSinistro7.get_Sinistros().FirstOrDefault(); if (sinistro6 != null) { motivo = sinistro6.get_Motivo(); } else { motivo = null; } } else { motivo = null; } relacaoIten.Motivo = motivo; relacaoIten.Status = (string.IsNullOrEmpty(x.get_Status()) ? x.get_StatusInclusao() : x.get_Status()); relacaoIten.Cobertura = (str.Length > 4000 ? str.Substring(0, 4000) : str); RelacaoItens endereco = relacaoIten; long id = this.SelectedControle.get_Controle().get_Ramo().get_Id(); if (id > (long)5) { if (id == (long)18) { endereco.Endereco = x.get_Patrimonial().get_Endereco(); endereco.Numero = x.get_Patrimonial().get_Numero(); endereco.Bairro = x.get_Patrimonial().get_Bairro(); endereco.Cidade = x.get_Patrimonial().get_Cidade(); endereco.Estado = x.get_Patrimonial().get_Estado(); endereco.Cep = x.get_Patrimonial().get_Cep(); endereco.Complemento = x.get_Patrimonial().get_Complemento(); endereco.Bens = x.get_Patrimonial().get_Bens(); endereco.Descricao = x.get_Descricao(); relacaoItens.Add(endereco); return; } if (id == (long)37) { goto Label1; } } else { if (id - (long)1 <= (long)2) { endereco.Endereco = x.get_Patrimonial().get_Endereco(); endereco.Numero = x.get_Patrimonial().get_Numero(); endereco.Bairro = x.get_Patrimonial().get_Bairro(); endereco.Cidade = x.get_Patrimonial().get_Cidade(); endereco.Estado = x.get_Patrimonial().get_Estado(); endereco.Cep = x.get_Patrimonial().get_Cep(); endereco.Complemento = x.get_Patrimonial().get_Complemento(); endereco.Bens = x.get_Patrimonial().get_Bens(); endereco.Descricao = x.get_Descricao(); relacaoItens.Add(endereco); return; } if (id == (long)5) { goto Label1; } } endereco.Descricao = x.get_Descricao(); relacaoItens.Add(endereco); return; Label1: endereco.Fipe = x.get_Auto().get_Fipe(); RelacaoItens relacaoIten1 = endereco; Fabricante fabricante = x.get_Auto().get_Fabricante(); if (fabricante != null) { descricao = fabricante.get_Descricao(); } else { descricao = null; } relacaoIten1.Fabricante = descricao; endereco.Modelo = x.get_Auto().get_Modelo(); endereco.AnoFab = x.get_Auto().get_AnoFabricacao(); endereco.AnoMod = x.get_Auto().get_AnoModelo(); endereco.Chassi = x.get_Auto().get_Chassi(); endereco.Placa = x.get_Auto().get_Placa(); endereco.RegiaoCirculacao = x.get_Auto().get_RegiaoCirculacao(); endereco.Bonus = x.get_Auto().get_Bonus(); endereco.Descricao = x.get_Descricao(); relacaoItens.Add(endereco); }); string tempPath = ""; str3 = ""; List configuracoes = Recursos.Configuracoes; if (!configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 41)) { tempPath = Path.GetTempPath(); str3 = string.Format("{0}{1}.xlsx", tempPath, Guid.NewGuid()); } else { using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) { if (DialogResult.OK == folderBrowserDialog.ShowDialog()) { tempPath = string.Concat(folderBrowserDialog.SelectedPath, "\\"); Directory.CreateDirectory(tempPath); } else { variable = null; str2 = null; str3 = null; return; } } object[] objArray = new object[] { tempPath, str2, this.SelectedControle.get_Apolice().Replace("/", ""), Guid.NewGuid() }; str3 = string.Format("{0}ITENS - {1} {2} {3}.xlsx", objArray); } XLWorkbook xLWorkbook = new XLWorkbook(); string apolice = this.SelectedControle.get_Apolice(); if (apolice != null) { str1 = apolice.Replace("/", ""); } else { str1 = null; } await Funcoes.GerarXls(xLWorkbook, string.Concat("ITENS - ", str1), relacaoItens, null).SaveAs(str3); if (!typeFromProgID) { await base.ShowMessage(string.Concat("ARQUIVO SALVO NO CAMINHO ", str3), "OK", "", false); } else { Process.Start(str3); } base.RegistrarAcao(string.Format("GEROU A RELAÇÃO DOS ITENS DO DOCUMENTO DE ID {0}", this.SelectedControle.get_Id()), this.SelectedControle.get_Id(), new TipoTela?(21), null); base.Loading(false); } } variable = null; str2 = null; str3 = null; } public void ManutecaoItens() { Action acessaTela = Gestor.Application.Actions.Actions.AcessaTela; if (acessaTela == null) { return; } acessaTela(3, "Manutencao"); } public async Task MostrarItens(int type = 0) { bool count; Item item; this.IsLoadingItens = false; this.MostrarItensVisibility = Visibility.Collapsed; this.MostrarSinistroVisibility = Visibility.Visible; this.ItensRevelados = true; Documento documentoSelecionado = ConsultaViewModel.DocumentoSelecionado; if (type == 1 && ConsultaViewModel.DocumentoSelecionado.get_Tipo() == 1) { documentoSelecionado = this.SelectedControle; } await this.CarregaItens(type, documentoSelecionado); ObservableCollection itens = this.Itens; if (itens != null) { count = itens.Count > 1; } else { count = false; } if (count) { ConsultaViewModel consultaViewModel = this; ObservableCollection observableCollection = this.Itens; if (observableCollection != null) { item = observableCollection.FirstOrDefault(); } else { item = null; } consultaViewModel.SelectedItem = item; } this.IsLoadingItens = true; } public async Task Pesquisar(PesquisaAvancada pesquisa) { TimeSpan vigencia1; string str; Visibility visibility; int num; int num1; string str1; ConsultaViewModel.u003cu003ec__DisplayClass24_0 variable; MainViewModel.StatusSelecionado = pesquisa.get_Status(); if (pesquisa.get_IdDocumento() != 0) { this.Pesquisando = true; await this.SelecionarCliente(pesquisa.get_IdCliente(), false); base.Loading(true); Documento documento = await this._apoliceServico.BuscarApoliceAsync(pesquisa.get_IdDocumento(), false, false); Documento documento1 = documento; if (documento1 == null || this.Apolices.Count == 0 || this.Apolices == null) { this.Pesquisando = false; base.Loading(false); } else { Documento documento2 = this.Apolices.FirstOrDefault((Documento x) => x.get_Controle().get_Id() == documento1.get_Controle().get_Id()); if (documento2 == null && documento1.get_Tipo() == 1) { documento2 = documento1; documento2.set_TemEndosso(true); if (documento2 == null) { this.Pesquisando = false; base.Loading(false); variable = null; return; } } this.SelectedControle = documento2; this.IsVisibleApolice = Visibility.Visible; this.VisibilityParcelasVendedores = Visibility.Collapsed; DateTime date = Funcoes.GetNetworkTime().Date; ConsultaViewModel consultaViewModel = this; if (string.IsNullOrEmpty(documento2.get_Apolice())) { vigencia1 = date - documento2.get_Vigencia1(); str = string.Format("{0} DIAS DE PENDÊNCIA", vigencia1.TotalDays); } else { str = ""; } consultaViewModel.PendenciaApolice = str; ConsultaViewModel consultaViewModel1 = this; visibility = (documento2.get_TemEndosso() ? Visibility.Visible : Visibility.Collapsed); consultaViewModel1.IsVisibleRadioEndosso = visibility; if (documento2.get_TemEndosso()) { this.IsVisibleRadioEndosso = Visibility.Visible; ConsultaViewModel observableCollection = this; IList documentos = documento2.get_Controle().get_Documentos(); observableCollection.Endossos = new ObservableCollection(documentos.Where((Documento x) => { if (x.get_Tipo() != 1) { return false; } return !x.get_Excluido(); })); } if (documento1.get_Tipo() == 1) { documento1 = this.Endossos.First((Documento x) => x.get_Id() == documento1.get_Id()); this.FilterDocumento = 1; this.IsVisibleEndosso = Visibility.Visible; this.SelectedEndosso = documento1; ConsultaViewModel consultaViewModel2 = this; if (string.IsNullOrEmpty(documento1.get_Endosso())) { vigencia1 = date - documento1.get_Vigencia1(); str1 = string.Format("{0} DIAS DE PENDÊNCIA", vigencia1.TotalDays); } else { str1 = ""; } consultaViewModel2.PendenciaApolice = str1; } this.CarregaDocumentos(documento1.get_Tipo()); await this.SelecionaParcelas(documento1); this.VisibilityParcelasVendedores = Visibility.Visible; this.Pesquisando = false; if (pesquisa.get_IdItem() != 0) { ConsultaViewModel consultaViewModel3 = this; num = (documento1.get_Tipo() == 0 ? 1 : 2); await consultaViewModel3.SelecionaItens(num, documento1, pesquisa.get_IdItem(), true); this.SelecionaItem(this.Itens.FirstOrDefault((Item x) => x.get_Id() == pesquisa.get_IdItem())); base.Loading(false); if (pesquisa.get_IdSinistro() != 0) { Action acessaTela = Gestor.Application.Actions.Actions.AcessaTela; if (acessaTela != null) { acessaTela(7, ""); } else { } } } else { ConsultaViewModel consultaViewModel4 = this; num1 = (documento1.get_Tipo() == 0 ? 1 : 2); await consultaViewModel4.SelecionaItens(num1, documento1, (long)0, false); base.Loading(false); } } } else { await this.SelecionarCliente(pesquisa.get_IdCliente(), true); } variable = null; } public async Task RecusarDocumento() { bool flag; IList list; string str; Documento documento; if (ConsultaViewModel.DocumentoSelecionado != null) { bool[] flagArray = await Funcoes.VerificarPagamento(ConsultaViewModel.DocumentoSelecionado.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 RECUSAR UMA APÓLICE ENQUANTO HOUVER RECEBIMENTO DE COMISSÃO OU PAGAMENTO DE VENDEDORES", "OK", "", false); documento = 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 = await this._apoliceServico.BuscarApoliceAsync(ConsultaViewModel.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() != ConsultaViewModel.DocumentoSelecionado.get_Id()) { await base.ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO ENQUANTO HOUVER ENDOSSOS EM CIMA DO MESMO.", "OK", "", false); documento = null; return; } } if (documento.get_Situacao() != 7) { if (documento.get_Tipo() != 0 || !string.IsNullOrEmpty(documento.get_Apolice())) { str = (documento.get_Tipo() != 0 || string.IsNullOrEmpty(documento.get_Apolice()) ? "O ENDOSSO SELECIONADO" : "A APÓLICE SELECIONADA"); } else { str = "A PROPOSTA SELECIONADA"; } string str1 = str; if (await base.ShowMessage(string.Concat("DESEJA REALMENTE RECUSAR ", str1, "?"), "SIM", "NÃO", false)) { string str2 = null; str2 = await base.ShowObservacaoDialog(); if (str2 != null) { base.Loading(true); await Funcoes.RecusarApolice(documento, str2, flag2); ConsultaViewModel.DocumentoSelecionado = null; await this.SelecionaCliente(this.SelectedCliente, true); base.Loading(false); } } } else { await base.ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO JÁ RECUSADO.", "OK", "", false); } } documento = null; } public async void SalvarOrdem(ObservableCollection itens) { if (itens != null) { ObservableCollection observableCollection = itens; if (!observableCollection.Any((Item x) => { int? ordem = x.get_Ordem(); return ordem.GetValueOrDefault() == 0 & ordem.HasValue; })) { ObservableCollection observableCollection1 = itens; IEnumerable> groupings = from item in observableCollection1 group item by item.get_Ordem(); if (!groupings.Any>((IGrouping x) => x.Count() > 1)) { base.Loading(true); foreach (Item iten in itens) { await this._itemServico.Save(iten); } await this.SelecionaItens(this.FilterItens, null, (long)0, false); base.Loading(false); } else { await base.ShowMessage("EXISTEM ITENS COM ORDEM REPETIDA. \nDEFINA UMA SEQUÊNCIA DIFERENTE PARA CADA ITEM.", "OK", "", false); } } else { await base.ShowMessage("O CAMPO ORDEM DEVE SER MAIOR QUE ZERO.", "OK", "", false); } } } public void ScrollDocumento() { if (this.UpdatingScroll) { return; } this.UpdatingScroll = true; Task.Run(async () => { await Task.Delay(300); System.Windows.Application.Current.Dispatcher.Invoke(() => { Action scrollDocumento = Gestor.Application.Actions.Actions.ScrollDocumento; if (scrollDocumento == null) { return; } scrollDocumento(); }); }); } public async Task SelecionaCliente(Cliente value, bool selecionar = true) { List vendedorUsuarios; long? nullable1; long? nullable2; string str; long? nullable3; Documento documento; long? nullable4; long? nullable5; long? nullable6; bool flag; Documento documento1; this.Clear(); if (value == null || value.get_Id() == 0) { base.IsVisible = Visibility.Collapsed; } else { try { this.Carregando = true; base.Loading(true); this.SelectedCliente = value; ApoliceServico apoliceServico = this._apoliceServico; long num = value.get_Id(); FiltroStatusDocumento statusSelecionado = MainViewModel.StatusSelecionado; if (Recursos.Usuario != null) { vendedorUsuarios = await base.VerificaVinculoVendedor(Recursos.Usuario); } else { vendedorUsuarios = new List(); } ObservableCollection observableCollection = await apoliceServico.BuscarApolicesAsync(num, statusSelecionado, vendedorUsuarios); apoliceServico = null; this.Apolices = observableCollection; ConsultaViewModel consultaViewModel = this; string[] nome = new string[] { "CONSULTOU ", null, null, null, null }; str = (MainViewModel.StatusSelecionado != 4 ? string.Concat("OS ", Functions.GetDescription(MainViewModel.StatusSelecionado)) : "TODOS OS DOCUMENTOS"); nome[1] = str; nome[2] = " DO CLIENTE \""; nome[3] = this.SelectedCliente.get_Nome(); nome[4] = "\""; string str1 = string.Concat(nome); long num1 = this.SelectedCliente.get_Id(); TipoTela? nullable7 = new TipoTela?(21); Cliente selectedCliente = this.SelectedCliente; if (selectedCliente != null) { nullable3 = new long?(selectedCliente.get_Id()); } else { nullable1 = null; nullable3 = nullable1; } consultaViewModel.RegistrarAcao(str1, num1, nullable7, string.Format("ID CLIENTE: {0}", nullable3)); if (this.Apolices == null || this.Apolices.Count <= 0) { this.SelectedControle = null; this.SelectedEndosso = null; this.SelectedItem = null; this.SelectedParcela = null; ConsultaViewModel.DocumentoSelecionado = null; ConsultaViewModel.ItemSelecionado = null; this.FilterDocumento = 0; this.IsVisibleRadioEndosso = Visibility.Collapsed; Action updateDocumento = Gestor.Application.Actions.Actions.UpdateDocumento; if (updateDocumento != null) { updateDocumento(null); } else { } } else if (selecionar) { if (ConsultaViewModel.DocumentoSelecionado != null && ConsultaViewModel.DocumentoSelecionado.get_Tipo() != 0) { Controle controle = ConsultaViewModel.DocumentoSelecionado.get_Controle(); if (controle != null) { Cliente cliente = controle.get_Cliente(); if (cliente != null) { nullable4 = new long?(cliente.get_Id()); } else { nullable2 = null; nullable4 = nullable2; } } else { nullable2 = null; nullable4 = nullable2; } nullable1 = nullable4; long num2 = value.get_Id(); if (nullable1.GetValueOrDefault() != num2 | !nullable1.HasValue) { goto Label2; } Controle controle1 = ConsultaViewModel.DocumentoSelecionado.get_Controle(); if (controle1 != null) { IList documentos = controle1.get_Documentos(); if (documentos != null) { Documento documento2 = documentos.FirstOrDefault((Documento x) => x.get_Tipo() == 0); if (documento2 != null) { nullable5 = new long?(documento2.get_Id()); } else { nullable1 = null; nullable5 = nullable1; } } else { nullable1 = null; nullable5 = nullable1; } } else { nullable1 = null; nullable5 = nullable1; } nullable1 = nullable5; long valueOrDefault = nullable1.GetValueOrDefault(); Documento documentoSelecionado = ConsultaViewModel.DocumentoSelecionado; if (documentoSelecionado != null) { nullable6 = new long?(documentoSelecionado.get_Id()); } else { nullable1 = null; nullable6 = nullable1; } long? nullable8 = nullable6; if (valueOrDefault > (long)0) { flag = this.Apolices.FirstOrDefault((Documento x) => x.get_Id() == valueOrDefault); } else { flag = false; } if (!flag) { ConsultaViewModel consultaViewModel1 = this; if (ConsultaViewModel.DocumentoSelecionado != null) { ObservableCollection apolices = this.Apolices; documento1 = apolices.FirstOrDefault((Documento x) => x.get_Id() == ConsultaViewModel.DocumentoSelecionado.get_Id()); if (documento1 == null) { documento1 = this.Apolices.FirstOrDefault(); } } else { documento1 = this.Apolices.FirstOrDefault(); } await consultaViewModel1.SelecionaDocumento(0, documento1); this.CarregaDocumentos(0); } else { await this.SelecionaDocumento(0, this.Apolices.FirstOrDefault((Documento x) => x.get_Id() == valueOrDefault)); this.FilterDocumento = 1; this.IsVisibleEndosso = Visibility.Visible; ConsultaViewModel consultaViewModel2 = this; Documento item = this.Endossos.FirstOrDefault((Documento x) => { long id = x.get_Id(); long? nullable = nullable8; return id == nullable.GetValueOrDefault() & nullable.HasValue; }); if (item == null) { item = this.Endossos[0]; } consultaViewModel2.SelectedEndosso = item; this.IsLoading = false; await this.WorkOnSelectedEndosso(this.SelectedEndosso); this.CarregaDocumentos(1); } goto Label1; } Label2: ConsultaViewModel consultaViewModel3 = this; if (ConsultaViewModel.DocumentoSelecionado != null) { ObservableCollection apolices1 = this.Apolices; documento = apolices1.FirstOrDefault((Documento x) => x.get_Id() == ConsultaViewModel.DocumentoSelecionado.get_Id()); if (documento == null) { documento = this.Apolices.FirstOrDefault(); } } else { documento = this.Apolices.FirstOrDefault(); } await consultaViewModel3.SelecionaDocumento(0, documento); this.CarregaDocumentos(0); } else { base.Loading(false); this.Carregando = false; return; } Label1: this.ManutencaoItemVisibility = Visibility.Visible; this.RenovarVisibility = Visibility.Visible; this.TrocarClienteVisibility = Visibility.Visible; this.TarefasVisibility = Visibility.Visible; this.EndossarVisibility = Visibility.Visible; this.ComissaoVisibility = Visibility.Visible; base.Loading(false); } catch (Exception exception1) { Exception exception = exception1; this.Clear(); this.SelectedControle = null; this.SelectedEndosso = null; this.SelectedItem = null; this.SelectedParcela = null; ConsultaViewModel.DocumentoSelecionado = null; ConsultaViewModel.ItemSelecionado = null; this.FilterDocumento = 0; this.IsVisibleRadioEndosso = Visibility.Collapsed; Action action = Gestor.Application.Actions.Actions.UpdateDocumento; if (action != null) { action(null); } else { } (new BaseServico()).Registrar(exception, 1, 3, new { @value = value, selecionar = selecionar }, true); } this.Carregando = false; } } public async Task SelecionaDocumento(int type, Documento documento) { if (!this.Pesquisando) { if (documento != null) { documento.get_Controle().get_Cliente().set_Nome(this.SelectedCliente.get_Nome()); if (type == 1) { this.FilterDocumento = 1; this.IsVisibleEndosso = Visibility.Visible; this.SelectedEndosso = documento; await this.WorkOnSelectedEndosso(documento); } else { this.FilterDocumento = 0; this.IsVisibleRadioEndosso = Visibility.Collapsed; this.IsVisibleApolice = Visibility.Visible; this.SelectedControle = documento; await this.WorkOnSelectedControle(documento); if (documento.get_TemEndosso()) { this.IsVisibleRadioEndosso = Visibility.Visible; ConsultaViewModel observableCollection = this; IList documentos = documento.get_Controle().get_Documentos(); observableCollection.Endossos = new ObservableCollection(documentos.Where((Documento x) => { if (x.get_Tipo() != 1) { return false; } if (Recursos.Usuario.get_Id() == 0) { return true; } return !x.get_Excluido(); })); } else { return; } } } else { this.FilterDocumento = 0; this.IsVisibleRadioEndosso = Visibility.Collapsed; this.IsVisibleApolice = Visibility.Visible; } } } public void SelecionaItem(Item item) { int num; if (item == null || item.get_Id() == 0) { return; } if (item != null) { long? substituido = item.get_Substituido(); long num1 = (long)0; if (substituido.GetValueOrDefault() <= num1 | !substituido.HasValue) { num = 0; this.FilterItens = num; this.SelectedItem = item; return; } num = 3; this.FilterItens = num; this.SelectedItem = item; return; } num = 0; this.FilterItens = num; this.SelectedItem = item; } public async Task SelecionaItens(int type, Documento documento = null, long iditem = 0L, bool pesquisaAvancada = false) { long? substituido; long num; Item item; Item item1; bool valueOrDefault; Item item2; Item item3; bool flag; Item item4; Item item5; if (documento == null) { documento = this.SelectedControle; } if (documento != null) { this.IsLoadingItens = false; bool flag1 = !pesquisaAvancada; if (flag1) { flag1 = await this.VerificaItens(documento); } if (!flag1) { await this.CarregaItens(type, documento); int filterItens = this.FilterItens; if (iditem == 0 && filterItens != 2) { ObservableCollection itens = this.Itens; if (itens != null) { item = itens.FirstOrDefault((Item i) => { long? nullable; long id = i.get_Id(); Item selectedItem = this.SelectedItem; if (selectedItem != null) { nullable = new long?(selectedItem.get_Id()); } else { nullable = null; } long? nullable1 = nullable; return id == nullable1.GetValueOrDefault() & nullable1.HasValue; }); } else { item = null; } Item item6 = item; if (item6 != null || filterItens == 0) { ConsultaViewModel consultaViewModel = this; if (item6 != null) { item1 = item6; } else { ObservableCollection observableCollection = this.Itens; if (observableCollection != null) { item1 = observableCollection.FirstOrDefault(); } else { item1 = null; } } consultaViewModel.SelectedItem = item1; } else if (item6 == null && filterItens == 1) { Item item7 = this.SelectedItem; if (item7 != null) { substituido = item7.get_Substituicao(); num = (long)0; flag = substituido.GetValueOrDefault() > num & substituido.HasValue; } else { flag = false; } if (flag) { ObservableCollection itens1 = this.Itens; if (itens1 != null) { item5 = itens1.FirstOrDefault((Item i) => { long? substituicao; long id = i.get_Id(); Item selectedItem = this.SelectedItem; if (selectedItem != null) { substituicao = selectedItem.get_Substituicao(); } else { substituicao = null; } long? nullable = substituicao; return id == nullable.GetValueOrDefault() & nullable.HasValue; }); } else { item5 = null; } item6 = item5; } ConsultaViewModel consultaViewModel1 = this; if (item6 != null) { item4 = item6; } else { ObservableCollection observableCollection1 = this.Itens; if (observableCollection1 != null) { item4 = observableCollection1.FirstOrDefault(); } else { item4 = null; } } consultaViewModel1.SelectedItem = item4; } Item item8 = this.SelectedItem; if (item8 != null) { substituido = item8.get_Substituido(); num = (long)0; valueOrDefault = substituido.GetValueOrDefault() > num & substituido.HasValue; } else { valueOrDefault = false; } if (valueOrDefault && filterItens != 1) { this.FilterItens = 3; this.Itens = await this._itemServico.BuscarItens(documento.get_Controle().get_Id(), 1); ObservableCollection itens2 = this.Itens; if (itens2 != null) { item2 = itens2.FirstOrDefault((Item i) => { long? nullable; long id = i.get_Id(); Item selectedItem = this.SelectedItem; if (selectedItem != null) { nullable = new long?(selectedItem.get_Id()); } else { nullable = null; } long? nullable1 = nullable; return id == nullable1.GetValueOrDefault() & nullable1.HasValue; }); } else { item2 = null; } item6 = item2; ConsultaViewModel consultaViewModel2 = this; if (item6 != null) { item3 = item6; } else { ObservableCollection observableCollection2 = this.Itens; if (observableCollection2 != null) { item3 = observableCollection2.FirstOrDefault(); } else { item3 = null; } } consultaViewModel2.SelectedItem = item3; } } this.IsLoadingItens = true; } } } public async Task SelecionaParcelas(Documento documento = null) { ObservableCollection observableCollection; Parcela item; if (documento == null) { documento = this.SelectedControle; } ObservableCollection observableCollection1 = await this._parcelaServico.BuscarParcelasPorDocumento(documento); ConsultaViewModel consultaViewModel = this; if (documento.get_TipoRecebimento().GetValueOrDefault() == 2) { ObservableCollection observableCollection2 = observableCollection1; observableCollection = new ObservableCollection( from x in observableCollection2 orderby x.get_NumeroParcela() descending select x); } else { observableCollection = observableCollection1; } consultaViewModel.Parcelas = observableCollection; ConsultaViewModel consultaViewModel1 = this; if (this.Parcelas == null || this.Parcelas.Count <= 0) { item = null; } else { item = this.Parcelas[0]; } consultaViewModel1.SelectedParcela = item; this.CalculaComissao(documento, this.Parcelas); this.IsLoadingParcelas = true; } public async void SelecionarCliente(Cliente cliente) { await this.SelecionaCliente(cliente, true); this.ScrollDocumento(); } public async Task SelecionarCliente(long id, bool selecionar) { Cliente cliente = await (new ClienteServico()).BuscarCliente(id); await this.SelecionaCliente(cliente, selecionar); } public async Task VerificaItens(Documento documento) { bool flag; if (!this.ItensRevelados) { if (await this._itemServico.ChecarQuantidade(documento.get_Id()) > 2) { this.Itens = new ObservableCollection(); ObservableCollection itens = this.Itens; Item item = new Item(); item.set_Id((long)0); item.set_Descricao("Item - Apólice Coletiva"); itens.Add(item); this.MostrarItensVisibility = Visibility.Visible; this.MostrarSinistroVisibility = Visibility.Collapsed; flag = true; return flag; } } flag = false; return flag; } private async Task WorkOnSelectedControle(Documento value) { string str; Visibility visibility; long id; if (value != null && value.get_Id() != 0 && !this.IsLoading) { ConsultaViewModel.DocumentoSelecionado = value; this.IsEnabledParcelaItem = false; this.IsLoading = true; this.VisibilityParcelasVendedores = Visibility.Collapsed; ConsultaViewModel consultaViewModel = this; if (string.IsNullOrEmpty(value.get_Apolice())) { DateTime networkTime = Funcoes.GetNetworkTime(); TimeSpan date = networkTime.Date - value.get_Vigencia1(); str = string.Format("{0} DIAS DE PENDÊNCIA", date.TotalDays); } else { str = ""; } consultaViewModel.PendenciaApolice = str; ConsultaViewModel consultaViewModel1 = this; visibility = (value.get_TemEndosso() ? Visibility.Visible : Visibility.Collapsed); consultaViewModel1.IsVisibleRadioEndosso = visibility; await this.SelecionaParcelas(value); this.VisibilityParcelasVendedores = Visibility.Visible; this.FilterItens = 0; Item itemSelecionado = ConsultaViewModel.ItemSelecionado; if (itemSelecionado != null) { id = itemSelecionado.get_Id(); } else { id = (long)0; } long num = id; await this.SelecionaItens(this.FilterItens, value, (long)0, false); if (num > (long)0 && this.Itens != null && this.Itens.Any((Item x) => x.get_Id() == num)) { ConsultaViewModel.ItemSelecionado = this.Itens.First((Item x) => x.get_Id() == num); this.SelecionaItem(ConsultaViewModel.ItemSelecionado); Action scrollToItem = Gestor.Application.Actions.Actions.ScrollToItem; if (scrollToItem != null) { scrollToItem(); } else { } } this.IsLoading = false; this.IsEnabledParcelaItem = true; } } private void WorkOnSelectedDocumento(Documento value) { if (value == null || value.get_Id() == 0 || this.Recarregando) { return; } ConsultaViewModel.DocumentoSelecionado = value; this.ParcelasLabel = (ConsultaViewModel.DocumentoSelecionado.get_TipoRecebimento().GetValueOrDefault() == 2 ? "FATURAS" : "PARCELAS"); TipoRecebimento? tipoRecebimento = ConsultaViewModel.DocumentoSelecionado.get_TipoRecebimento(); this.IsFatura = tipoRecebimento.GetValueOrDefault() == 2; Action updateDocumento = Gestor.Application.Actions.Actions.UpdateDocumento; if (updateDocumento == null) { return; } updateDocumento(value); } private async Task WorkOnSelectedEndosso(Documento value) { string str; long id; Visibility visibility; string apolice; if (value != null && value.get_Id() != 0 && !this.IsLoading) { ConsultaViewModel.DocumentoSelecionado = value; base.IsEnabled = false; this.IsLoading = true; this.VisibilityParcelasVendedores = Visibility.Collapsed; ConsultaViewModel consultaViewModel = this; if (string.IsNullOrEmpty(value.get_Endosso())) { DateTime networkTime = Funcoes.GetNetworkTime(); TimeSpan date = networkTime.Date - value.get_Vigencia1(); str = string.Format("{0} DIAS DE PENDÊNCIA", date.TotalDays); } else { str = ""; } consultaViewModel.PendenciaApolice = str; await this.SelecionaParcelas(value); Item itemSelecionado = ConsultaViewModel.ItemSelecionado; if (itemSelecionado != null) { id = itemSelecionado.get_Id(); } else { id = (long)0; } long num = id; await this.SelecionaItens(this.FilterItens, null, (long)0, false); if (num > (long)0 && this.Itens != null && this.Itens.Any((Item x) => x.get_Id() == num)) { ConsultaViewModel.ItemSelecionado = this.Itens.First((Item x) => x.get_Id() == num); this.SelecionaItem(ConsultaViewModel.ItemSelecionado); Action scrollToItem = Gestor.Application.Actions.Actions.ScrollToItem; if (scrollToItem != null) { scrollToItem(); } else { } } this.VisibilityParcelasVendedores = Visibility.Visible; ConsultaViewModel consultaViewModel1 = this; List configuracoes = Recursos.Configuracoes; if (configuracoes.Any((ConfiguracaoSistema x) => x.get_Configuracao() == 19)) { Documento documento = value; if (documento != null) { apolice = documento.get_Apolice(); } else { apolice = null; } if (string.IsNullOrWhiteSpace(apolice) || !value.get_Emissao().HasValue) { goto Label1; } visibility = Visibility.Collapsed; goto Label0; } Label1: visibility = Visibility.Visible; Label0: consultaViewModel1.RecusaVisibility = visibility; base.IsEnabled = true; this.IsLoading = false; } } private static void WorkOnSelectedItem(Item value) { long? nullable; if (value != null) { Item itemSelecionado = ConsultaViewModel.ItemSelecionado; if (itemSelecionado != null) { nullable = new long?(itemSelecionado.get_Id()); } else { nullable = null; } long? nullable1 = nullable; long id = value.get_Id(); if (nullable1.GetValueOrDefault() == id & nullable1.HasValue) { return; } } ConsultaViewModel.ItemSelecionado = value; Action updateItem = Gestor.Application.Actions.Actions.UpdateItem; if (updateItem == null) { return; } updateItem(value); } } }