diff options
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Seguros/ConsultaViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels.Seguros/ConsultaViewModel.cs | 1685 |
1 files changed, 1685 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Seguros/ConsultaViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Seguros/ConsultaViewModel.cs new file mode 100644 index 0000000..a41d428 --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Seguros/ConsultaViewModel.cs @@ -0,0 +1,1685 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Forms; +using System.Windows.Threading; +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.Generic; +using Gestor.Model.API; +using Gestor.Model.Common; +using Gestor.Model.Domain.Common; +using Gestor.Model.Domain.Configuracoes; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +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)2; + + private Cliente _selectedCliente = new Cliente(); + + private bool _carregando; + + private bool _isLoading; + + private Visibility _visibilityParcelasVendedores; + + private ObservableCollection<Documento> _apolices = new ObservableCollection<Documento>(); + + private ObservableCollection<Documento> _endossos = new ObservableCollection<Documento>(); + + 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<Item> _itens = new ObservableCollection<Item>(); + + private Parcela _selectedParcela = new Parcela(); + + private ObservableCollection<Parcela> _parcelas = new ObservableCollection<Parcela>(); + + private Visibility _isVisibleRadioEndosso = (Visibility)2; + + private Visibility _isVisibleEndosso = (Visibility)2; + + private Visibility _isVisibleApolice; + + private string _pendenciaApolice = ""; + + private Visibility _isVisiblePendenciaApolice = (Visibility)2; + + 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)2; + + private Visibility _mostrarSinistroVisibility; + + private ObservableCollection<ClienteTelefone> _telefones = new ObservableCollection<ClienteTelefone>(); + + public static Documento DocumentoSelecionado + { + get + { + return _documentoSelecionado; + } + set + { + _documentoSelecionado = value; + Gestor.Application.Actions.Actions.EnableItens?.Invoke(value != null && ((DomainBase)value).Id > 0); + Gestor.Application.Actions.Actions.EnableDocumento?.Invoke(value != null && ((DomainBase)value).Id > 0); + } + } + + public static Documento DocumentoRenovado { get; set; } + + public bool Apelido + { + get + { + return _apelido; + } + set + { + _apelido = value; + OnPropertyChanged("Apelido"); + } + } + + public bool Pesquisando { get; set; } + + public Visibility SemDocumentos + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _semDocumentos; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _semDocumentos = value; + OnPropertyChanged("SemDocumentos"); + } + } + + public Cliente SelectedCliente + { + get + { + return _selectedCliente; + } + set + { + _selectedCliente = value; + OnPropertyChanged("SelectedCliente"); + } + } + + public bool Carregando + { + get + { + return _carregando; + } + set + { + _carregando = value; + SemDocumentos = (Visibility)((value || (Apolices != null && Apolices.Count != 0)) ? 2 : 0); + } + } + + public bool IsLoading + { + get + { + return _isLoading; + } + set + { + _isLoading = value; + OnPropertyChanged("IsLoading"); + } + } + + public Visibility VisibilityParcelasVendedores + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _visibilityParcelasVendedores; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _visibilityParcelasVendedores = value; + OnPropertyChanged("VisibilityParcelasVendedores"); + } + } + + public ObservableCollection<Documento> Apolices + { + get + { + return _apolices; + } + set + { + _apolices = value; + OnPropertyChanged("Apolices"); + } + } + + public ObservableCollection<Documento> Endossos + { + get + { + return _endossos; + } + set + { + _endossos = value; + OnPropertyChanged("Endossos"); + } + } + + public Documento SelectedEndosso + { + get + { + return _selectedEndosso; + } + set + { + _selectedEndosso = value; + WorkOnSelectedDocumento(value); + OnPropertyChanged("SelectedEndosso"); + } + } + + public string ParcelasLabel + { + get + { + return _parcelasLabel; + } + set + { + _parcelasLabel = value; + OnPropertyChanged("ParcelasLabel"); + } + } + + public Documento SelectedControle + { + get + { + return _selectedControle; + } + set + { + _selectedControle = value; + int enableButtons; + if (value != null && ((DomainBase)value).Id > 0) + { + Usuario usuario = Recursos.Usuario; + enableButtons = ((usuario != null && ((DomainBase)usuario).Id > 0) ? 1 : 0); + } + else + { + enableButtons = 0; + } + base.EnableButtons = (byte)enableButtons != 0; + bool flag = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 13); + base.EnableEndossar = value != null && ((DomainBase)value).Id > 0 && (flag || (!string.IsNullOrWhiteSpace(value.Apolice) && !string.IsNullOrWhiteSpace(value.Proposta) && value.Emissao.HasValue)); + base.EnableRenovar = value != null && ((DomainBase)value).Id > 0 && value.Vigencia2.HasValue && !string.IsNullOrWhiteSpace(value.Apolice); + WorkOnSelectedDocumento(value); + RecusaVisibility = (Visibility)((Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 19) && !string.IsNullOrWhiteSpace((value != null) ? value.Apolice : null) && value.Emissao.HasValue) ? 2 : 0); + ItensRevelados = false; + MostrarItensVisibility = (Visibility)2; + MostrarSinistroVisibility = (Visibility)0; + OnPropertyChanged("SelectedControle"); + } + } + + public bool IsFatura + { + get + { + return _isFatura; + } + set + { + //IL_0004: Unknown result type (might be due to invalid IL or missing references) + //IL_000a: Invalid comparison between Unknown and I4 + if (!value) + { + value = (int)ComissaoValorVisibility == 2; + } + _isFatura = value; + OnPropertyChanged("IsFatura"); + } + } + + public bool Recarregando { get; set; } + + public bool IsEnabledParcelaItem + { + get + { + return _isEnabledParcelaItem; + } + set + { + _isEnabledParcelaItem = value; + OnPropertyChanged("IsEnabledParcelaItem"); + } + } + + public Item SelectedItem + { + get + { + return _selectedItem; + } + set + { + _selectedItem = value; + WorkOnSelectedItem(value); + OnPropertyChanged("SelectedItem"); + } + } + + public ObservableCollection<Item> Itens + { + get + { + return _itens; + } + set + { + _itens = value; + OnPropertyChanged("Itens"); + } + } + + public Parcela SelectedParcela + { + get + { + return _selectedParcela; + } + set + { + _selectedParcela = value; + OnPropertyChanged("SelectedParcela"); + } + } + + public ObservableCollection<Parcela> Parcelas + { + get + { + return _parcelas; + } + set + { + _parcelas = value; + OnPropertyChanged("Parcelas"); + } + } + + public Visibility IsVisibleRadioEndosso + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _isVisibleRadioEndosso; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _isVisibleRadioEndosso = value; + OnPropertyChanged("IsVisibleRadioEndosso"); + } + } + + public Visibility IsVisibleEndosso + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _isVisibleEndosso; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _isVisibleEndosso = value; + OnPropertyChanged("IsVisibleEndosso"); + } + } + + public Visibility IsVisibleApolice + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _isVisibleApolice; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _isVisibleApolice = value; + OnPropertyChanged("IsVisibleApolice"); + } + } + + public string PendenciaApolice + { + get + { + return _pendenciaApolice; + } + set + { + _pendenciaApolice = value; + IsVisiblePendenciaApolice = (Visibility)(string.IsNullOrEmpty(_pendenciaApolice) ? 2 : 0); + OnPropertyChanged("PendenciaApolice"); + } + } + + public Visibility IsVisiblePendenciaApolice + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _isVisiblePendenciaApolice; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _isVisiblePendenciaApolice = value; + OnPropertyChanged("IsVisiblePendenciaApolice"); + } + } + + public decimal Gerada + { + get + { + return _gerada; + } + set + { + _gerada = value; + OnPropertyChanged("Gerada"); + } + } + + public decimal Recebida + { + get + { + return _recebida; + } + set + { + _recebida = value; + OnPropertyChanged("Recebida"); + } + } + + public decimal Pendente + { + get + { + return _pendente; + } + set + { + _pendente = value; + OnPropertyChanged("Pendente"); + } + } + + public bool IsLoadingParcelas + { + get + { + return _isLoadingParcelas; + } + set + { + _isLoadingParcelas = value; + OnPropertyChanged("IsLoadingParcelas"); + } + } + + public bool IsLoadingItens + { + get + { + return _isLoadingItens; + } + set + { + _isLoadingItens = value; + OnPropertyChanged("IsLoadingItens"); + } + } + + public static int FiltrarItens { get; set; } + + public int FilterItens + { + get + { + return _filterItens; + } + set + { + _filterItens = value; + FiltrarItens = value; + OnPropertyChanged("FilterItens"); + } + } + + public int FilterDocumento + { + get + { + return _filterDocumento; + } + set + { + _filterDocumento = value; + Gestor.Application.Actions.Actions.UpdateRadioApolice?.Invoke(_filterDocumento); + OnPropertyChanged("FilterDocumento"); + } + } + + public Visibility ManutencaoItemVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _manutencaoItemVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _manutencaoItemVisibility = (Visibility)(Restricao((TipoRestricao)22) ? 2 : ((int)value)); + OnPropertyChanged("ManutencaoItemVisibility"); + } + } + + public Visibility RecusaVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _recusaVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _recusaVisibility = (Visibility)(Restricao((TipoRestricao)18) ? 2 : ((int)value)); + OnPropertyChanged("RecusaVisibility"); + } + } + + public Visibility RenovarVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _renovarVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _renovarVisibility = (Visibility)(Restricao((TipoRestricao)17) ? 2 : ((int)value)); + OnPropertyChanged("RenovarVisibility"); + } + } + + public Visibility EndossarVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _endossarVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _endossarVisibility = (Visibility)(Restricao((TipoRestricao)33) ? 2 : ((int)value)); + OnPropertyChanged("EndossarVisibility"); + } + } + + public Visibility TrocarClienteVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _trocarClienteVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _trocarClienteVisibility = (Visibility)(Restricao((TipoRestricao)21) ? 2 : ((int)value)); + OnPropertyChanged("TrocarClienteVisibility"); + } + } + + public Visibility TarefasVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _tarefasVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _tarefasVisibility = (Visibility)((!Permissao((TipoTela)38)) ? 2 : ((int)value)); + OnPropertyChanged("TarefasVisibility"); + } + } + + public Visibility ComissaoVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _comissaoVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _comissaoVisibility = (Visibility)(Restricao((TipoRestricao)95) ? 2 : ((int)value)); + OnPropertyChanged("ComissaoVisibility"); + } + } + + public Visibility ComissaoValorVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _comissaoValorVisibility; + } + set + { + //IL_000e: Unknown result type (might be due to invalid IL or missing references) + //IL_000f: Unknown result type (might be due to invalid IL or missing references) + _comissaoValorVisibility = (Visibility)(Restricao((TipoRestricao)14) ? 2 : ((int)value)); + OnPropertyChanged("ComissaoValorVisibility"); + } + } + + public Visibility MostrarItensVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _mostrarItensVisibility; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _mostrarItensVisibility = value; + OnPropertyChanged("MostrarItensVisibility"); + } + } + + public Visibility MostrarSinistroVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _mostrarSinistroVisibility; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _mostrarSinistroVisibility = value; + OnPropertyChanged("MostrarSinistroVisibility"); + } + } + + public bool ItensRevelados { get; set; } + + public ObservableCollection<ClienteTelefone> Telefones + { + get + { + return _telefones; + } + set + { + _telefones = value; + OnPropertyChanged("Telefones"); + } + } + + public ConsultaViewModel() + { + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + //IL_0008: Unknown result type (might be due to invalid IL or missing references) + //IL_0012: Expected O, but got Unknown + //IL_0029: Unknown result type (might be due to invalid IL or missing references) + //IL_0033: Expected O, but got Unknown + //IL_003f: Unknown result type (might be due to invalid IL or missing references) + //IL_0049: Expected O, but got Unknown + //IL_0051: Unknown result type (might be due to invalid IL or missing references) + //IL_005b: Expected O, but got Unknown + //IL_0067: Unknown result type (might be due to invalid IL or missing references) + //IL_0071: Expected O, but got Unknown + //IL_007e: Unknown result type (might be due to invalid IL or missing references) + //IL_0085: Unknown result type (might be due to invalid IL or missing references) + //IL_0097: Unknown result type (might be due to invalid IL or missing references) + //IL_00ac: Unknown result type (might be due to invalid IL or missing references) + _apoliceServico = new ApoliceServico(); + _parcelaServico = new ParcelaServico(); + _vendedorServico = new VendedorServico(); + _itemServico = new ItemServico(); + Apelido = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 6); + SemDocumentos = (Visibility)0; + base.EnableButtons = false; + if (MainViewModel.ClienteSelecionado != null && ((DomainBase)MainViewModel.ClienteSelecionado).Id > 0) + { + SelecionarCliente(MainViewModel.ClienteSelecionado); + } + } + + public async Task Pesquisar(PesquisaAvancada pesquisa) + { + MainViewModel.StatusSelecionado = pesquisa.Status; + if (pesquisa.IdDocumento == 0L) + { + await SelecionarCliente(pesquisa.IdCliente, selecionar: true); + return; + } + Pesquisando = true; + await SelecionarCliente(pesquisa.IdCliente, selecionar: false); + Loading(isLoading: true); + Documento documento = await _apoliceServico.BuscarApoliceAsync(pesquisa.IdDocumento); + if (documento == null || Apolices.Count == 0 || Apolices == null) + { + Pesquisando = false; + Loading(isLoading: false); + return; + } + Documento val = ((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x.Controle).Id == ((DomainBase)documento.Controle).Id)); + if (val == null && documento.Tipo == 1) + { + val = documento; + val.TemEndosso = true; + if (val == null) + { + Pesquisando = false; + Loading(isLoading: false); + return; + } + } + SelectedControle = val; + IsVisibleApolice = (Visibility)0; + VisibilityParcelasVendedores = (Visibility)2; + DateTime date = Funcoes.GetNetworkTime().Date; + PendenciaApolice = (string.IsNullOrEmpty(val.Apolice) ? $"{(date - val.Vigencia1).TotalDays} DIAS DE PENDÊNCIA" : ""); + IsVisibleRadioEndosso = (Visibility)((!val.TemEndosso) ? 2 : 0); + if (val.TemEndosso) + { + IsVisibleRadioEndosso = (Visibility)0; + Endossos = new ObservableCollection<Documento>(val.Controle.Documentos.Where((Documento x) => x.Tipo == 1 && !x.Excluido)); + } + if (documento.Tipo == 1) + { + documento = Endossos.First((Documento x) => ((DomainBase)x).Id == ((DomainBase)documento).Id); + FilterDocumento = 1; + IsVisibleEndosso = (Visibility)0; + SelectedEndosso = documento; + PendenciaApolice = (string.IsNullOrEmpty(documento.Endosso) ? $"{(date - documento.Vigencia1).TotalDays} DIAS DE PENDÊNCIA" : ""); + } + CarregaDocumentos(documento.Tipo); + await SelecionaParcelas(documento); + VisibilityParcelasVendedores = (Visibility)0; + Pesquisando = false; + if (pesquisa.IdItem == 0L) + { + await SelecionaItens((documento.Tipo == 0) ? 1 : 2, documento, 0L); + Loading(isLoading: false); + return; + } + await SelecionaItens((documento.Tipo == 0) ? 1 : 2, documento, pesquisa.IdItem, pesquisaAvancada: true); + SelecionaItem(((IEnumerable<Item>)Itens).FirstOrDefault((Func<Item, bool>)((Item x) => ((DomainBase)x).Id == pesquisa.IdItem))); + Loading(isLoading: false); + if (pesquisa.IdSinistro != 0L) + { + Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)7, ""); + } + } + + public async void SelecionarCliente(Cliente cliente) + { + await SelecionaCliente(cliente); + ScrollDocumento(); + } + + public void ScrollDocumento() + { + if (UpdatingScroll) + { + return; + } + UpdatingScroll = true; + Task.Run(async delegate + { + await Task.Delay(300); + ((DispatcherObject)Application.Current).Dispatcher.Invoke((Action)delegate + { + Gestor.Application.Actions.Actions.ScrollDocumento?.Invoke(); + }); + }); + } + + public async Task SelecionarCliente(long id, bool selecionar) + { + await SelecionaCliente(await new ClienteServico().BuscarCliente(id), selecionar); + } + + public async Task SelecionaCliente(Cliente value, bool selecionar = true) + { + Clear(); + if (value == null || ((DomainBase)value).Id == 0L) + { + base.IsVisible = (Visibility)2; + return; + } + try + { + Carregando = true; + Loading(isLoading: true); + SelectedCliente = value; + ApoliceServico apoliceServico = _apoliceServico; + long id = ((DomainBase)value).Id; + FiltroStatusDocumento statusSelecionado = MainViewModel.StatusSelecionado; + List<VendedorUsuario> vendedorVinculado = ((Recursos.Usuario != null) ? (await VerificaVinculoVendedor(Recursos.Usuario)) : new List<VendedorUsuario>()); + Apolices = await apoliceServico.BuscarApolicesAsync(id, statusSelecionado, vendedorVinculado); + ConsultaViewModel consultaViewModel = this; + string descricao = "CONSULTOU " + (((int)MainViewModel.StatusSelecionado != 4) ? ("OS " + Functions.GetDescription((Enum)(object)MainViewModel.StatusSelecionado)) : "TODOS OS DOCUMENTOS") + " DO CLIENTE \"" + SelectedCliente.Nome + "\""; + long id2 = ((DomainBase)SelectedCliente).Id; + TipoTela? tela = (TipoTela)21; + Cliente selectedCliente = SelectedCliente; + consultaViewModel.RegistrarAcao(descricao, id2, tela, $"ID CLIENTE: {((selectedCliente != null) ? new long?(((DomainBase)selectedCliente).Id) : null)}"); + if (Apolices != null && Apolices.Count > 0) + { + if (!selecionar) + { + Loading(isLoading: false); + Carregando = false; + return; + } + if (DocumentoSelecionado != null && DocumentoSelecionado.Tipo != 0) + { + Controle controle = DocumentoSelecionado.Controle; + long? obj; + if (controle == null) + { + obj = null; + } + else + { + Cliente cliente = controle.Cliente; + obj = ((cliente != null) ? new long?(((DomainBase)cliente).Id) : null); + } + if (obj == ((DomainBase)value).Id) + { + Controle controle2 = DocumentoSelecionado.Controle; + long? obj2; + if (controle2 == null) + { + obj2 = null; + } + else + { + IList<Documento> documentos = controle2.Documentos; + if (documentos == null) + { + obj2 = null; + } + else + { + Documento? obj3 = ((IEnumerable<Documento>)documentos).FirstOrDefault((Func<Documento, bool>)((Documento x) => x.Tipo == 0)); + obj2 = ((obj3 != null) ? new long?(((DomainBase)obj3).Id) : null); + } + } + long? num = obj2; + long documentId = num.GetValueOrDefault(); + Documento documentoSelecionado = DocumentoSelecionado; + long? endossoId = ((documentoSelecionado != null) ? new long?(((DomainBase)documentoSelecionado).Id) : null); + if (((documentId > 0) ? ((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == documentId)) : null) != null) + { + await SelecionaDocumento(0, ((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == documentId))); + FilterDocumento = 1; + IsVisibleEndosso = (Visibility)0; + SelectedEndosso = ((IEnumerable<Documento>)Endossos).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == endossoId)) ?? Endossos[0]; + IsLoading = false; + await WorkOnSelectedEndosso(SelectedEndosso); + CarregaDocumentos(1); + } + else + { + await SelecionaDocumento(0, (DocumentoSelecionado != null) ? (((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == ((DomainBase)DocumentoSelecionado).Id)) ?? Apolices.FirstOrDefault()) : Apolices.FirstOrDefault()); + CarregaDocumentos(0); + } + goto IL_06af; + } + } + await SelecionaDocumento(0, (DocumentoSelecionado != null) ? (((IEnumerable<Documento>)Apolices).FirstOrDefault((Func<Documento, bool>)((Documento x) => ((DomainBase)x).Id == ((DomainBase)DocumentoSelecionado).Id)) ?? Apolices.FirstOrDefault()) : Apolices.FirstOrDefault()); + CarregaDocumentos(0); + } + else + { + SelectedControle = null; + SelectedEndosso = null; + SelectedItem = null; + SelectedParcela = null; + DocumentoSelecionado = null; + ItemSelecionado = null; + FilterDocumento = 0; + IsVisibleRadioEndosso = (Visibility)2; + Gestor.Application.Actions.Actions.UpdateDocumento?.Invoke(null); + } + goto IL_06af; + IL_06af: + ManutencaoItemVisibility = (Visibility)0; + RenovarVisibility = (Visibility)0; + TrocarClienteVisibility = (Visibility)0; + TarefasVisibility = (Visibility)0; + EndossarVisibility = (Visibility)0; + ComissaoVisibility = (Visibility)0; + Loading(isLoading: false); + } + catch (Exception e) + { + Clear(); + SelectedControle = null; + SelectedEndosso = null; + SelectedItem = null; + SelectedParcela = null; + DocumentoSelecionado = null; + ItemSelecionado = null; + FilterDocumento = 0; + IsVisibleRadioEndosso = (Visibility)2; + Gestor.Application.Actions.Actions.UpdateDocumento?.Invoke(null); + new BaseServico().Registrar(e, (TipoErro)1, 3, new { value, selecionar }); + } + Carregando = false; + } + + private void Clear() + { + Apolices = null; + Parcelas = null; + Itens = null; + } + + private async Task WorkOnSelectedEndosso(Documento value) + { + if (value == null || ((DomainBase)value).Id == 0L || IsLoading) + { + return; + } + DocumentoSelecionado = value; + base.IsEnabled = false; + IsLoading = true; + VisibilityParcelasVendedores = (Visibility)2; + PendenciaApolice = (string.IsNullOrEmpty(value.Endosso) ? $"{(Funcoes.GetNetworkTime().Date - value.Vigencia1).TotalDays} DIAS DE PENDÊNCIA" : ""); + await SelecionaParcelas(value); + Item itemSelecionado = ItemSelecionado; + long item = ((itemSelecionado != null) ? ((DomainBase)itemSelecionado).Id : 0); + await SelecionaItens(FilterItens, null, 0L); + if (item > 0 && Itens != null && Itens.Any((Item x) => ((DomainBase)x).Id == item)) + { + ItemSelecionado = Itens.First((Item x) => ((DomainBase)x).Id == item); + SelecionaItem(ItemSelecionado); + Gestor.Application.Actions.Actions.ScrollToItem?.Invoke(); + } + VisibilityParcelasVendedores = (Visibility)0; + ConsultaViewModel consultaViewModel = this; + int num; + if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 19)) + { + if (!string.IsNullOrWhiteSpace((value != null) ? value.Apolice : null) && value.Emissao.HasValue) + { + num = 2; + goto IL_027b; + } + } + num = 0; + goto IL_027b; + IL_027b: + consultaViewModel.RecusaVisibility = (Visibility)num; + base.IsEnabled = true; + IsLoading = false; + } + + private void WorkOnSelectedDocumento(Documento value) + { + //IL_0028: Unknown result type (might be due to invalid IL or missing references) + //IL_002e: Invalid comparison between Unknown and I4 + //IL_004f: Unknown result type (might be due to invalid IL or missing references) + //IL_0055: Invalid comparison between Unknown and I4 + if (value != null && ((DomainBase)value).Id != 0L && !Recarregando) + { + DocumentoSelecionado = value; + ParcelasLabel = (((int)DocumentoSelecionado.TipoRecebimento.GetValueOrDefault() == 2) ? "FATURAS" : "PARCELAS"); + IsFatura = (int)DocumentoSelecionado.TipoRecebimento.GetValueOrDefault() == 2; + Gestor.Application.Actions.Actions.UpdateDocumento?.Invoke(value); + } + } + + private async Task WorkOnSelectedControle(Documento value) + { + if (value == null || ((DomainBase)value).Id == 0L || IsLoading) + { + return; + } + DocumentoSelecionado = value; + IsEnabledParcelaItem = false; + IsLoading = true; + VisibilityParcelasVendedores = (Visibility)2; + PendenciaApolice = (string.IsNullOrEmpty(value.Apolice) ? $"{(Funcoes.GetNetworkTime().Date - value.Vigencia1).TotalDays} DIAS DE PENDÊNCIA" : ""); + IsVisibleRadioEndosso = (Visibility)((!value.TemEndosso) ? 2 : 0); + await SelecionaParcelas(value); + VisibilityParcelasVendedores = (Visibility)0; + FilterItens = 0; + Item itemSelecionado = ItemSelecionado; + long item = ((itemSelecionado != null) ? ((DomainBase)itemSelecionado).Id : 0); + await SelecionaItens(FilterItens, value, 0L); + if (item > 0 && Itens != null && Itens.Any((Item x) => ((DomainBase)x).Id == item)) + { + ItemSelecionado = Itens.First((Item x) => ((DomainBase)x).Id == item); + SelecionaItem(ItemSelecionado); + Gestor.Application.Actions.Actions.ScrollToItem?.Invoke(); + } + IsLoading = false; + IsEnabledParcelaItem = true; + } + + private void CalculaComissao(Documento documento, ObservableCollection<Parcela> parcelas) + { + decimal num = (documento.AdicionalComiss ? (documento.PremioLiquido + documento.PremioAdicional) : documento.PremioLiquido); + decimal num2 = documento.Comissao * 0.01m; + Gerada = num * num2; + Recebida = (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 32) ? parcelas.Where((Parcela x) => (int)x.SubTipo == 1 || (int)x.SubTipo == 6).Sum((Parcela x) => x.ValorComissao) : parcelas.Where((Parcela x) => (int)x.SubTipo == 1).Sum((Parcela x) => x.ValorComissao)); + Pendente = Gerada - Recebida; + Pendente = ((Pendente < 0.01m) ? 0.00m : Pendente); + } + + public async Task SelecionaParcelas(Documento documento = null) + { + if (documento == null) + { + documento = SelectedControle; + } + ObservableCollection<Parcela> observableCollection = await _parcelaServico.BuscarParcelasPorDocumento(documento); + Parcelas = (((int)documento.TipoRecebimento.GetValueOrDefault() == 2) ? new ObservableCollection<Parcela>(observableCollection.OrderByDescending((Parcela x) => x.NumeroParcela)) : observableCollection); + SelectedParcela = ((Parcelas != null && Parcelas.Count > 0) ? Parcelas[0] : null); + CalculaComissao(documento, Parcelas); + IsLoadingParcelas = true; + } + + public async Task SelecionaItens(int type, Documento documento = null, long iditem = 0L, bool pesquisaAvancada = false) + { + if (documento == null) + { + documento = SelectedControle; + } + if (documento == null) + { + return; + } + IsLoadingItens = false; + bool flag = !pesquisaAvancada; + if (flag) + { + flag = await VerificaItens(documento); + } + if (flag) + { + return; + } + await CarregaItens(type, documento); + int filterItens = FilterItens; + if (iditem == 0L && filterItens != 2) + { + Item val = Itens?.FirstOrDefault((Func<Item, bool>)delegate(Item i) + { + long id3 = ((DomainBase)i).Id; + Item selectedItem5 = SelectedItem; + return id3 == ((selectedItem5 != null) ? new long?(((DomainBase)selectedItem5).Id) : null); + }); + if (val != null || filterItens == 0) + { + SelectedItem = (Item)((val != null) ? ((object)val) : ((object)Itens?.FirstOrDefault())); + } + else if (val == null && filterItens == 1) + { + Item selectedItem = SelectedItem; + if (selectedItem != null && selectedItem.Substituicao > 0) + { + val = Itens?.FirstOrDefault((Func<Item, bool>)delegate(Item i) + { + long id2 = ((DomainBase)i).Id; + Item selectedItem4 = SelectedItem; + return id2 == ((selectedItem4 != null) ? selectedItem4.Substituicao : null); + }); + } + SelectedItem = (Item)((val != null) ? ((object)val) : ((object)Itens?.FirstOrDefault())); + } + Item selectedItem2 = SelectedItem; + if (selectedItem2 != null && selectedItem2.Substituido > 0 && filterItens != 1) + { + FilterItens = 3; + Itens = await _itemServico.BuscarItens(((DomainBase)documento.Controle).Id, (StatusItem)1); + val = Itens?.FirstOrDefault((Func<Item, bool>)delegate(Item i) + { + long id = ((DomainBase)i).Id; + Item selectedItem3 = SelectedItem; + return id == ((selectedItem3 != null) ? new long?(((DomainBase)selectedItem3).Id) : null); + }); + SelectedItem = (Item)((val != null) ? ((object)val) : ((object)Itens?.FirstOrDefault())); + } + } + IsLoadingItens = true; + } + + public async Task<bool> VerificaItens(Documento documento) + { + if (!ItensRevelados && await _itemServico.ChecarQuantidade(((DomainBase)documento).Id) > 2) + { + Itens = new ObservableCollection<Item>(); + Itens.Add(new Item + { + Id = 0L, + Descricao = "Item - Apólice Coletiva" + }); + MostrarItensVisibility = (Visibility)0; + MostrarSinistroVisibility = (Visibility)2; + return true; + } + return false; + } + + public async Task MostrarItens(int type = 0) + { + IsLoadingItens = false; + MostrarItensVisibility = (Visibility)2; + MostrarSinistroVisibility = (Visibility)0; + ItensRevelados = true; + Documento documento = DocumentoSelecionado; + if (type == 1 && DocumentoSelecionado.Tipo == 1) + { + documento = SelectedControle; + } + await CarregaItens(type, documento); + ObservableCollection<Item> itens = Itens; + if (itens != null && itens.Count > 1) + { + SelectedItem = Itens?.FirstOrDefault(); + } + IsLoadingItens = true; + } + + public async Task CarregaItens(int type, Documento documento) + { + FilterItens = 0; + switch (type) + { + case 0: + Itens = await _itemServico.BuscarItens(((DomainBase)documento.Controle).Id, (StatusItem)0); + break; + case 1: + FilterItens = 1; + Itens = await _itemServico.BuscarItens(((DomainBase)documento).Id, (StatusItem)2); + break; + case 2: + FilterItens = 2; + documento = SelectedEndosso ?? documento; + Itens = await _itemServico.BuscarItens(((DomainBase)documento).Id, (StatusItem)2); + break; + case 3: + FilterItens = 3; + Itens = await _itemServico.BuscarItens(((DomainBase)documento.Controle).Id, (StatusItem)1); + break; + } + } + + public async Task SelecionaDocumento(int type, Documento documento) + { + if (Pesquisando) + { + return; + } + if (documento == null) + { + FilterDocumento = 0; + IsVisibleRadioEndosso = (Visibility)2; + IsVisibleApolice = (Visibility)0; + return; + } + documento.Controle.Cliente.Nome = SelectedCliente.Nome; + if (type != 1) + { + FilterDocumento = 0; + IsVisibleRadioEndosso = (Visibility)2; + IsVisibleApolice = (Visibility)0; + SelectedControle = documento; + await WorkOnSelectedControle(documento); + if (documento.TemEndosso) + { + IsVisibleRadioEndosso = (Visibility)0; + Endossos = new ObservableCollection<Documento>(documento.Controle.Documentos.Where((Documento x) => x.Tipo == 1 && (((DomainBase)Recursos.Usuario).Id == 0L || !x.Excluido))); + } + } + else + { + FilterDocumento = 1; + IsVisibleEndosso = (Visibility)0; + SelectedEndosso = documento; + await WorkOnSelectedEndosso(documento); + } + } + + public void CarregaDocumentos(int type) + { + IsVisibleApolice = (Visibility)2; + IsVisibleEndosso = (Visibility)2; + if (type != 1) + { + IsVisibleApolice = (Visibility)0; + } + else + { + IsVisibleEndosso = (Visibility)0; + } + } + + public void SelecionaItem(Item item) + { + if (item != null && ((DomainBase)item).Id != 0L) + { + FilterItens = ((item != null && item.Substituido > 0) ? 3 : 0); + SelectedItem = item; + } + } + + private static void WorkOnSelectedItem(Item value) + { + if (value != null) + { + Item itemSelecionado = ItemSelecionado; + if (((itemSelecionado != null) ? new long?(((DomainBase)itemSelecionado).Id) : null) == ((DomainBase)value).Id) + { + return; + } + } + ItemSelecionado = value; + Gestor.Application.Actions.Actions.UpdateItem?.Invoke(value); + } + + public async Task<Documento> AbrirDetalhes() + { + Documento documento = SelectedControle; + if (FilterDocumento == 1) + { + documento = SelectedEndosso ?? SelectedControle; + } + Documento val = documento; + val.Pagamentos = await _vendedorServico.BuscaRepasse(((DomainBase)documento).Id); + val = documento; + val.Parcelas = await _parcelaServico.BuscarParcelasAsync(((DomainBase)documento).Id); + return documento; + } + + public async Task EditarParcelas() + { + await ShowEditarParcelasDialog(DocumentoSelecionado); + await SelecionaParcelas(DocumentoSelecionado); + } + + public async Task RecusarDocumento() + { + if (DocumentoSelecionado == null) + { + return; + } + bool[] array = await Funcoes.VerificarPagamento(((DomainBase)DocumentoSelecionado).Id); + if (Recursos.Configuracoes.All((ConfiguracaoSistema x) => (int)x.Configuracao != 23) && array.Any((bool x) => x)) + { + await ShowMessage("NÃO É POSSÍVEL RECUSAR UMA APÓLICE ENQUANTO HOUVER RECEBIMENTO DE COMISSÃO OU PAGAMENTO DE VENDEDORES"); + return; + } + bool flag = Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 23) && array[1]; + if (flag) + { + flag = await ShowMessage("EXISTEM PAGAMENTOS PARA OS VENDEDORES DO CONTRATO, DESEJA CRIAR ESTORNOS PARA ESSES PAGAMENTOS?", "SIM", "NÃO"); + } + bool estorno = flag; + Documento documento = await _apoliceServico.BuscarApoliceAsync(((DomainBase)DocumentoSelecionado).Id); + IList<Documento> list; + if (documento.Controle.Documentos.Count <= 1) + { + list = documento.Controle.Documentos; + } + else + { + IList<Documento> list2 = (from x in documento.Controle.Documentos + where !x.Excluido + orderby x.Ordem + select x).ToList(); + list = list2; + } + IList<Documento> list3 = list; + if (list3.Count > 1 && ((DomainBase)list3.Last((Documento x) => (int)x.Situacao != 7)).Id != ((DomainBase)DocumentoSelecionado).Id) + { + await ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO ENQUANTO HOUVER ENDOSSOS EM CIMA DO MESMO."); + return; + } + if ((int)documento.Situacao == 7) + { + await ShowMessage("NÃO É POSSÍVEL RECUSAR UM DOCUMENTO JÁ RECUSADO."); + return; + } + string text = ((documento.Tipo == 0 && string.IsNullOrEmpty(documento.Apolice)) ? "A PROPOSTA SELECIONADA" : ((documento.Tipo == 0 && !string.IsNullOrEmpty(documento.Apolice)) ? "A APÓLICE SELECIONADA" : "O ENDOSSO SELECIONADO")); + if (await ShowMessage("DESEJA REALMENTE RECUSAR " + text + "?", "SIM", "NÃO")) + { + string text2 = await ShowObservacaoDialog(); + if (text2 != null) + { + Loading(isLoading: true); + await Funcoes.RecusarApolice(documento, text2, estorno); + DocumentoSelecionado = null; + await SelecionaCliente(SelectedCliente); + Loading(isLoading: false); + } + } + } + + public async Task<Parcela> AbrirDetalhesParcela() + { + Parcela parcela = SelectedParcela; + parcela.Vendedores = new ObservableCollection<VendedorParcela>(await _vendedorServico.BuscaRepasseParcela(((DomainBase)parcela).Id)); + return parcela; + } + + public void ManutecaoItens() + { + Gestor.Application.Actions.Actions.AcessaTela?.Invoke((TipoTela)3, "Manutencao"); + } + + public async Task GerarExcel(int type) + { + if (SelectedControle == null) + { + return; + } + Loading(isLoading: true); + bool iniciar = Type.GetTypeFromProgID("Excel.Application") != null; + string descricao = "ATIVOS"; + ObservableCollection<Item> observableCollection; + switch (type) + { + default: + observableCollection = await _itemServico.BuscarItems(((DomainBase)SelectedControle.Controle).Id, (StatusItem)0, sinsitroCompleto: true); + break; + case 1: + descricao = "DA APÓLICE"; + observableCollection = await _itemServico.BuscarItems(((DomainBase)SelectedControle).Id, (StatusItem)2, sinsitroCompleto: true); + break; + case 2: + { + Documento val = SelectedEndosso ?? SelectedControle; + descricao = ((SelectedEndosso == null) ? "DA APÓLICE" : "DO ENDOSSO"); + observableCollection = await _itemServico.BuscarItems(((DomainBase)val).Id, (StatusItem)2, sinsitroCompleto: true); + break; + } + case 3: + descricao = "INATIVOS"; + observableCollection = await _itemServico.BuscarItems(((DomainBase)SelectedControle.Controle).Id, (StatusItem)1, sinsitroCompleto: true); + break; + } + if (observableCollection == null || observableCollection.Count == 0) + { + Loading(isLoading: false); + await ShowMessage("NÃO HÁ ITENS PARA EXIBIR A RELAÇÃO"); + return; + } + List<RelacaoItens> itensList = new List<RelacaoItens>(); + observableCollection.ToList().ForEach(delegate(Item x) + { + string Coberturas = ""; + if (x.Coberturas.Count() > 0) + { + x.Coberturas.ToList().ForEach(delegate(Cobertura c) + { + Coberturas += $"Cobertura: {c.Observacao} | Premio: {c.Premio} | Franquia: {c.Franquia} | LMI: {c.Lmi}\n"; + }); + } + RelacaoItens obj = new RelacaoItens + { + Nome = SelectedCliente.Nome, + Documento = SelectedCliente.Documento, + Apolice = SelectedControle.Apolice, + VigenciaInicial = SelectedControle.Vigencia1, + VigenciaFinal = SelectedControle.Vigencia2, + Ordem = x.Ordem, + Sinistrado = (x.Sinistrado ? "SIM" : "NÃO") + }; + ControleSinistro? obj2 = x.Sinistros.FirstOrDefault(); + obj.DataSinistro = ((obj2 != null) ? obj2.DataSinistro : null); + ControleSinistro? obj3 = x.Sinistros.FirstOrDefault(); + object numSinistro; + if (obj3 == null) + { + numSinistro = null; + } + else + { + Sinistro? obj4 = obj3.Sinistros.FirstOrDefault(); + numSinistro = ((obj4 != null) ? obj4.Numero : null); + } + obj.NumSinistro = (string)numSinistro; + ControleSinistro? obj5 = x.Sinistros.FirstOrDefault(); + StatusSinistro? statusSinistro; + if (obj5 == null) + { + statusSinistro = null; + } + else + { + Sinistro? obj6 = obj5.Sinistros.FirstOrDefault(); + statusSinistro = ((obj6 != null) ? obj6.StatusSinistro : null); + } + obj.StatusSinistro = statusSinistro; + ControleSinistro? obj7 = x.Sinistros.FirstOrDefault(); + object itemSinistrado; + if (obj7 == null) + { + itemSinistrado = null; + } + else + { + Sinistro? obj8 = obj7.Sinistros.FirstOrDefault(); + itemSinistrado = ((obj8 != null) ? obj8.ItemSinistrado : null); + } + obj.ItemSinistrado = (string)itemSinistrado; + ControleSinistro? obj9 = x.Sinistros.FirstOrDefault(); + decimal? valor; + if (obj9 == null) + { + valor = null; + } + else + { + Sinistro? obj10 = obj9.Sinistros.FirstOrDefault(); + valor = ((obj10 != null) ? new decimal?(obj10.Valor) : null); + } + obj.Valor = valor; + ControleSinistro? obj11 = x.Sinistros.FirstOrDefault(); + DateTime? dataLiq; + if (obj11 == null) + { + dataLiq = null; + } + else + { + Sinistro? obj12 = obj11.Sinistros.FirstOrDefault(); + dataLiq = ((obj12 != null) ? obj12.DataLiquidacao : null); + } + obj.DataLiq = dataLiq; + ControleSinistro? obj13 = x.Sinistros.FirstOrDefault(); + DateTime? dataRec; + if (obj13 == null) + { + dataRec = null; + } + else + { + Sinistro? obj14 = obj13.Sinistros.FirstOrDefault(); + dataRec = ((obj14 != null) ? obj14.DataReclamacao : null); + } + obj.DataRec = dataRec; + ControleSinistro? obj15 = x.Sinistros.FirstOrDefault(); + object motivo; + if (obj15 == null) + { + motivo = null; + } + else + { + Sinistro? obj16 = obj15.Sinistros.FirstOrDefault(); + motivo = ((obj16 != null) ? obj16.Motivo : null); + } + obj.Motivo = (string)motivo; + obj.Status = (string.IsNullOrEmpty(x.Status) ? x.StatusInclusao : x.Status); + obj.Cobertura = ((Coberturas.Length > 4000) ? Coberturas.Substring(0, 4000) : Coberturas); + RelacaoItens relacaoItens = obj; + switch (((DomainBase)SelectedControle.Controle.Ramo).Id) + { + case 1L: + case 2L: + case 3L: + case 18L: + relacaoItens.Endereco = ((EnderecoBase)x.Patrimonial).Endereco; + relacaoItens.Numero = ((EnderecoBase)x.Patrimonial).Numero; + relacaoItens.Bairro = ((EnderecoBase)x.Patrimonial).Bairro; + relacaoItens.Cidade = ((EnderecoBase)x.Patrimonial).Cidade; + relacaoItens.Estado = ((EnderecoBase)x.Patrimonial).Estado; + relacaoItens.Cep = ((EnderecoBase)x.Patrimonial).Cep; + relacaoItens.Complemento = ((EnderecoBase)x.Patrimonial).Complemento; + relacaoItens.Bens = x.Patrimonial.Bens; + relacaoItens.Descricao = x.Descricao; + break; + case 5L: + case 37L: + { + relacaoItens.Fipe = x.Auto.Fipe; + Fabricante fabricante = x.Auto.Fabricante; + relacaoItens.Fabricante = ((fabricante != null) ? fabricante.Descricao : null); + relacaoItens.Modelo = x.Auto.Modelo; + relacaoItens.AnoFab = x.Auto.AnoFabricacao; + relacaoItens.AnoMod = x.Auto.AnoModelo; + relacaoItens.Chassi = x.Auto.Chassi; + relacaoItens.Placa = x.Auto.Placa; + relacaoItens.RegiaoCirculacao = x.Auto.RegiaoCirculacao; + relacaoItens.Bonus = x.Auto.Bonus; + relacaoItens.Descricao = x.Descricao; + break; + } + default: + relacaoItens.Descricao = x.Descricao; + break; + } + itensList.Add(relacaoItens); + }); + string text = ""; + string fileName; + if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 41)) + { + FolderBrowserDialog val2 = new FolderBrowserDialog(); + try + { + if (1 != (int)((CommonDialog)val2).ShowDialog()) + { + return; + } + text = val2.SelectedPath + "\\"; + Directory.CreateDirectory(text); + } + finally + { + ((IDisposable)val2)?.Dispose(); + } + fileName = string.Format("{0}ITENS - {1} {2} {3}.xlsx", text, descricao, SelectedControle.Apolice.Replace("/", ""), Guid.NewGuid()); + } + else + { + text = Path.GetTempPath(); + fileName = $"{text}{Guid.NewGuid()}.xlsx"; + } + (await Funcoes.GerarXls(new XLWorkbook(), "ITENS - " + SelectedControle.Apolice?.Replace("/", ""), itensList)).SaveAs(fileName); + if (!iniciar) + { + await ShowMessage("ARQUIVO SALVO NO CAMINHO " + fileName); + } + else + { + Process.Start(fileName); + } + RegistrarAcao($"GEROU A RELAÇÃO DOS ITENS DO DOCUMENTO DE ID {((DomainBase)SelectedControle).Id}", ((DomainBase)SelectedControle).Id, (TipoTela)21); + Loading(isLoading: false); + } + + public async void SalvarOrdem(ObservableCollection<Item> itens) + { + if (itens == null) + { + return; + } + if (itens.Any((Item x) => x.Ordem == 0)) + { + await ShowMessage("O CAMPO ORDEM DEVE SER MAIOR QUE ZERO."); + return; + } + if ((from item in itens + group item by item.Ordem).Any((IGrouping<int?, Item> x) => x.Count() > 1)) + { + await ShowMessage("EXISTEM ITENS COM ORDEM REPETIDA. \nDEFINA UMA SEQUÊNCIA DIFERENTE PARA CADA ITEM."); + return; + } + Loading(isLoading: true); + foreach (Item iten in itens) + { + await _itemServico.Save(iten); + } + await SelecionaItens(FilterItens, null, 0L); + Loading(isLoading: false); + } + + public async Task<string> CreateLink(Documento documento) + { + if (documento == null || SelectedCliente == null) + { + return ""; + } + Telefones = new ObservableCollection<ClienteTelefone>(await new ClienteServico().BuscarTelefonesAsync(((DomainBase)SelectedCliente).Id)); + object obj2; + if (Itens != null) + { + if (Itens.Count <= 1) + { + Item? obj = Itens.FirstOrDefault(); + obj2 = ((obj != null) ? obj.Descricao : null); + } + else + { + obj2 = "APÓLICE COLETIVA"; + } + } + else + { + obj2 = ""; + } + string item = (string)obj2; + return await CreateLinkAssistencia(documento, item); + } +} |