From 225aa1499e37faf9d38257caabbadc68d78b427e Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 12:29:41 -0300 Subject: decompiler.com --- .../ReciboViewModel.cs | 537 +++++++++++++++++++++ 1 file changed, 537 insertions(+) create mode 100644 Decompiler/Gestor.Application.ViewModels.Ferramentas/ReciboViewModel.cs (limited to 'Decompiler/Gestor.Application.ViewModels.Ferramentas/ReciboViewModel.cs') diff --git a/Decompiler/Gestor.Application.ViewModels.Ferramentas/ReciboViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Ferramentas/ReciboViewModel.cs new file mode 100644 index 0000000..81e4e8f --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Ferramentas/ReciboViewModel.cs @@ -0,0 +1,537 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Ferramentas; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Common; +using Gestor.Model.Domain.Ferramentas; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; + +namespace Gestor.Application.ViewModels.Ferramentas; + +public class ReciboViewModel : BaseSegurosViewModel +{ + private readonly ReciboServico _servico; + + public Recibo CancelRecibo; + + private Recibo _selectedRecibo = new Recibo(); + + private DateTime? _horaRecibo; + + private ObservableCollection _recibosFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + private Cliente _pagante; + + private Cliente _recebedor; + + public List Recibos { get; set; } + + public Recibo SelectedRecibo + { + get + { + return _selectedRecibo; + } + set + { + _selectedRecibo = value; + WorkOnSelectedRecibo(value); + VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); + if (!value.DataRecibo.HasValue) + { + value.DataRecibo = DateTime.Now; + } + if (value != null) + { + HoraRecibo = value.DataRecibo; + } + OnPropertyChanged("SelectedRecibo"); + } + } + + public DateTime? HoraRecibo + { + get + { + return _horaRecibo; + } + set + { + _horaRecibo = value; + if (value.HasValue) + { + SelectedRecibo.DataRecibo = (SelectedRecibo.DataRecibo.HasValue ? new DateTime?(DateTime.Parse($"{SelectedRecibo.DataRecibo.Value:d} {value:T}")) : null); + OnPropertyChanged("HoraRecibo"); + } + } + } + + public ObservableCollection RecibosFiltrados + { + get + { + return _recibosFiltrados; + } + set + { + _recibosFiltrados = value; + IsExpanded = value != null && value.Count > 0; + OnPropertyChanged("RecibosFiltrados"); + } + } + + public bool IsExpanded + { + get + { + return _isExpanded; + } + set + { + _isExpanded = value; + OnPropertyChanged("IsExpanded"); + } + } + + public Cliente Pagante + { + get + { + return _pagante; + } + set + { + _pagante = value; + WorkOnSelectedPagante(value); + OnPropertyChanged("Pagante"); + } + } + + public Cliente Recebedor + { + get + { + return _recebedor; + } + set + { + _recebedor = value; + WorkOnSelectedRecebedor(value); + OnPropertyChanged("Recebedor"); + } + } + + public ReciboViewModel() + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Expected O, but got Unknown + _servico = new ReciboServico(); + base.EnableMenu = true; + Seleciona(); + } + + private void WorkOnSelectedPagante(Cliente value) + { + if (value != null) + { + SelectedRecibo.Pagante = Regex.Replace(value.NomeSocial, "\\-\\s\\d.*", "").Trim(); + SelectedRecibo.DocumentoPagante = value.Documento; + SelectedRecibo = SelectedRecibo; + } + } + + private void WorkOnSelectedRecebedor(Cliente value) + { + if (value != null) + { + SelectedRecibo.Recebedor = Regex.Replace(value.NomeSocial, "\\-\\s\\d.*", "").Trim(); + SelectedRecibo.DocumentoRecebedor = value.Documento; + SelectedRecibo = SelectedRecibo; + } + } + + private async void Seleciona() + { + Loading(isLoading: true); + await PermissaoTela((TipoTela)42); + await SelecionaRecibo(); + Loading(isLoading: false); + } + + private async Task SelecionaRecibo() + { + Loading(isLoading: true); + Recibos = (await _servico.BuscarRecibos()).ToList(); + RecibosFiltrados = new ObservableCollection(Recibos); + if (RecibosFiltrados.Count > 0) + { + SelectedRecibo = RecibosFiltrados.First(); + } + else + { + SelectedRecibo = new Recibo(); + Alterar(alterar: false); + base.EnableMenu = false; + } + Loading(isLoading: false); + } + + public void Incluir() + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Expected O, but got Unknown + SelectedRecibo = new Recibo(); + Alterar(alterar: true); + } + + internal async Task> Filtrar(string value) + { + return await Task.Run(() => FiltrarRecibo(value)); + } + + public List FiltrarRecibo(string filter) + { + RecibosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(Recibos) : new ObservableCollection(Recibos.Where((Recibo x) => ValidationHelper.RemoveDiacritics(x.Pagante.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) || ValidationHelper.RemoveDiacritics(x.Recebedor).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))))); + return RecibosFiltrados.ToList(); + } + + public async Task>> Salvar() + { + List> list = SelectedRecibo.Validate(); + if (list.Count > 0) + { + return list; + } + string acao = ((((DomainBase)SelectedRecibo).Id == 0L) ? "INCLUIU" : "ALTEROU"); + Recibo value = await _servico.Save(SelectedRecibo); + if (!_servico.Sucesso) + { + return null; + } + ReciboViewModel reciboViewModel = this; + string descricao = $"{acao} RECIBO DE NÚMERO \"{((DomainBase)value).Id}\""; + long id = ((DomainBase)value).Id; + TipoTela? tela = (TipoTela)42; + object[] obj = new object[9] + { + value.Tipo.HasValue ? (ValidationHelper.GetDescription((Enum)(object)value.Tipo.Value) ?? "") : "-", + null, + null, + null, + null, + null, + null, + null, + null + }; + TipoPagamento? pagamento = value.Pagamento; + obj[1] = (pagamento.HasValue ? ValidationHelper.GetDescription((Enum)(object)pagamento.GetValueOrDefault()) : null); + obj[2] = value.Valor; + obj[3] = value.DataRecibo; + obj[4] = value.Pagante; + obj[5] = value.DocumentoPagante; + obj[6] = value.Recebedor; + obj[7] = value.DocumentoRecebedor; + obj[8] = value.Referente; + reciboViewModel.RegistrarAcao(descricao, id, tela, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", obj)); + if (Recibos.Any((Recibo x) => ((DomainBase)x).Id == ((DomainBase)value).Id)) + { + DomainBase.Copy(Recibos.First((Recibo x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value); + } + else + { + Recibos.Add(value); + } + if (RecibosFiltrados.Any((Recibo x) => ((DomainBase)x).Id == ((DomainBase)value).Id)) + { + DomainBase.Copy(RecibosFiltrados.First((Recibo x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value); + } + else + { + RecibosFiltrados.Add(value); + } + RecibosFiltrados = new ObservableCollection(RecibosFiltrados); + WorkOnSelectedRecibo(value, registrar: false); + Alterar(alterar: false); + ToggleSnackBar("RECIBO SALVO COM SUCESSO"); + return null; + } + + public async void Excluir() + { + if (SelectedRecibo != null && ((DomainBase)SelectedRecibo).Id != 0L && await ShowMessage("DESEJA REALMENTE EXCLUIR O RECIBO PERMANENTEMENTE?", "SIM", "NÃO")) + { + Loading(isLoading: true); + if (!(await _servico.Delete(SelectedRecibo))) + { + Loading(isLoading: false); + return; + } + ReciboViewModel reciboViewModel = this; + string descricao = $"EXCLUIU RECIBO DE NÚMERO \"{((DomainBase)SelectedRecibo).Id}\""; + long id = ((DomainBase)SelectedRecibo).Id; + TipoTela? tela = (TipoTela)42; + object[] obj = new object[9] + { + SelectedRecibo.Tipo.HasValue ? (ValidationHelper.GetDescription((Enum)(object)SelectedRecibo.Tipo.Value) ?? "") : "-", + null, + null, + null, + null, + null, + null, + null, + null + }; + TipoPagamento? pagamento = SelectedRecibo.Pagamento; + obj[1] = (pagamento.HasValue ? ValidationHelper.GetDescription((Enum)(object)pagamento.GetValueOrDefault()) : null); + obj[2] = SelectedRecibo.Valor; + obj[3] = SelectedRecibo.DataRecibo; + obj[4] = SelectedRecibo.Pagante; + obj[5] = SelectedRecibo.DocumentoPagante; + obj[6] = SelectedRecibo.Recebedor; + obj[7] = SelectedRecibo.DocumentoRecebedor; + obj[8] = SelectedRecibo.Referente; + reciboViewModel.RegistrarAcao(descricao, id, tela, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", obj)); + await SelecionaRecibo(); + Loading(isLoading: false); + ToggleSnackBar("RECIBO EXCLUÍDO COM SUCESSO"); + } + } + + public void CancelarAlteracao() + { + if (CancelRecibo != null && Recibos.Any((Recibo x) => ((DomainBase)x).Id == ((DomainBase)CancelRecibo).Id)) + { + DomainBase.Copy(Recibos.First((Recibo x) => ((DomainBase)x).Id == ((DomainBase)CancelRecibo).Id), CancelRecibo); + if (RecibosFiltrados.Count > 0 && RecibosFiltrados.Any((Recibo x) => ((DomainBase)x).Id == ((DomainBase)CancelRecibo).Id)) + { + DomainBase.Copy(RecibosFiltrados.First((Recibo x) => ((DomainBase)x).Id == ((DomainBase)CancelRecibo).Id), CancelRecibo); + } + else + { + RecibosFiltrados.Add(CancelRecibo); + } + RecibosFiltrados = new ObservableCollection(RecibosFiltrados); + SelectedRecibo = RecibosFiltrados.First((Recibo x) => ((DomainBase)x).Id == ((DomainBase)CancelRecibo).Id); + } + else + { + Incluir(); + } + Alterar(alterar: false); + } + + private bool IsImage(string extensao) + { + if (extensao == null) + { + return false; + } + if (extensao.ToLower().Contains("jpg")) + { + return true; + } + if (extensao.ToLower().Contains("jpeg")) + { + return true; + } + if (extensao.ToLower().Contains("png")) + { + return true; + } + return false; + } + + public async void Print() + { + Recibo selectedRecibo = SelectedRecibo; + if (((selectedRecibo != null) ? selectedRecibo.Referente : null) == null || SelectedRecibo.Recebedor == null) + { + return; + } + ArquivoDigital arquivo = null; + List list = await ArquivoDigitalServico.BuscarPorTipo((TipoArquivoDigital)13, ((DomainBase)Recursos.Empresa).Id); + if (list != null && list.Any((IndiceArquivoDigital x) => x.Descricao == "LOGO")) + { + IndiceArquivoDigital? obj = ((IEnumerable)list).FirstOrDefault((Func)((IndiceArquivoDigital x) => x.Descricao == "LOGO")); + long? num = ((obj != null) ? new long?(obj.IdArquivoDigital) : null); + IndiceArquivoDigital? obj2 = ((IEnumerable)list).FirstOrDefault((Func)((IndiceArquivoDigital x) => x.Descricao == "LOGO")); + string banco = ((obj2 != null) ? obj2.Bd : null); + if (num.HasValue) + { + arquivo = await ArquivoDigitalServico.BuscarPorId(num.Value, banco); + } + } + ArquivoDigital obj3 = arquivo; + byte[] array = ((obj3 != null) ? obj3.Arquivo : null); + string image = ""; + if (array != null && array.Length != 0) + { + ReciboViewModel reciboViewModel = this; + ArquivoDigital obj4 = arquivo; + if (reciboViewModel.IsImage((obj4 != null) ? obj4.Extensao : null)) + { + ArquivoDigital obj5 = arquivo; + image = GetImage(array, (obj5 != null) ? obj5.Extensao : null); + } + } + string longDatePattern = new CultureInfo("pt-PT", useUserOverride: false).DateTimeFormat.LongDatePattern; + string data = SelectedRecibo.DataRecibo?.ToString(longDatePattern, new CultureInfo("pt-PT")); + int vias = ((!(await ShowMessage("DESEJA IMPRIMIR DUAS VIAS DO RECIBO?", "SIM", "NÃO"))) ? 1 : 2); + bool flag = !string.IsNullOrEmpty(image); + if (flag) + { + flag = await ShowMessage("DESEJA IMPRIMIR O LOGO DA CORRETORA NO RECIBO?\nPARA ADICIONAR UM LOGO, É NECESSÁRIO COLOCÁ-LO NO ARQUIVO\nDIGITAL NA TELA DE EMPRESA E FILIAIS COM DESCRIÇÃO \"LOGO\"", "SIM", "NÃO"); + } + bool flag2 = flag; + string text = "RECIBO"; + for (int i = 0; i < vias; i++) + { + if (flag2) + { + text = text + "
" + image + "
"; + text += "
"; + } + else + { + text += "
"; + } + text += $"
N° {((DomainBase)SelectedRecibo).Id}

"; + text += "R E C I B O

"; + if ((int)SelectedRecibo.Tipo.GetValueOrDefault() == 1) + { + string text2 = ((SelectedRecibo.DocumentoRecebedor == null || SelectedRecibo.DocumentoRecebedor.Clear().Length < 12) ? "EU" : "A"); + string text3 = ((SelectedRecibo.DocumentoRecebedor == null || SelectedRecibo.DocumentoRecebedor.Clear().Length < 12) ? "CPF" : "CNPJ"); + string text4 = ((text2 == "EU") ? "O" : "A"); + string text5 = ((text2 == "EU") ? "RECEBI" : "RECEBEU"); + text += $"PELO PRESENTE, {text2}, {SelectedRecibo.Recebedor}, INSCRIT{text4} NO {text3} SOB Nº {SelectedRecibo.DocumentoRecebedor}, DECLAR{text4} QUE {text5}, NA DATA DE HOJE, {SelectedRecibo.DataRecibo:dd/MM/yyyy HH:mm}, O VALOR DE R$ {SelectedRecibo.Valor:0.00} POR MEIO DE {ValidationHelper.GetDescription((Enum)(object)SelectedRecibo.Pagamento)}, DE {SelectedRecibo.Pagante}, INSCRITO NO CPF/CNPJ SOB Nº {SelectedRecibo.DocumentoPagante}, REFERENTE À(AO) {SelectedRecibo.Referente.ToUpper()}. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.
"; + text = text + "" + ((EnderecoBase)Recursos.Empresa).Cidade + ", " + data?.ToUpper() + ".

"; + text = text + "_________________________________
ASSINATURA " + SelectedRecibo.Recebedor + "
" + SelectedRecibo.DocumentoRecebedor; + } + else + { + string text6 = ((SelectedRecibo.DocumentoPagante == null || SelectedRecibo.DocumentoPagante.Clear().Length < 12) ? "EU" : "A"); + string text7 = ((SelectedRecibo.DocumentoPagante == null || SelectedRecibo.DocumentoPagante.Clear().Length < 12) ? "CPF" : "CNPJ"); + string text8 = ((text6 == "EU") ? "O" : "A"); + string text9 = ((text6 == "EU") ? "PAGUEI" : "PAGOU"); + text += $"PELO PRESENTE, {text6}, {SelectedRecibo.Pagante}, INSCRIT{text8} NO {text7} SOB Nº {SelectedRecibo.DocumentoPagante}, DECLAR{text8} QUE {text9}, NA DATA DE HOJE, {SelectedRecibo.DataRecibo:dd/MM/yyyy HH:mm}, O VALOR DE R$ {SelectedRecibo.Valor:0.00} POR MEIO DE {ValidationHelper.GetDescription((Enum)(object)SelectedRecibo.Pagamento)}, PARA {SelectedRecibo.Recebedor}, INSCRITO NO CPF/CNPJ SOB Nº {SelectedRecibo.DocumentoRecebedor}, REFERENTE À(AO) {SelectedRecibo.Referente.ToUpper()}. DANDO-LHE POR ESTE RECIBO A DEVIDA QUITAÇÃO.
"; + text = text + "
" + ((EnderecoBase)Recursos.Empresa).Cidade + ", " + data?.ToUpper() + ".

"; + text = text + "_________________________________
ASSINATURA " + SelectedRecibo.Recebedor + "
" + SelectedRecibo.DocumentoRecebedor; + } + text += "
"; + } + text += " "; + string tempPath = Path.GetTempPath(); + string text10 = $"{tempPath}_{Funcoes.GetNetworkTime():ddMMyyyyhhmmss}.html"; + StreamWriter streamWriter = new StreamWriter(text10, append: true, Encoding.UTF8); + streamWriter.Write(text); + streamWriter.Close(); + Process.Start(text10); + ReciboViewModel reciboViewModel2 = this; + string descricao = $"IMPRIMIU O RECIBO DE NÚMERO \"{((DomainBase)SelectedRecibo).Id}\""; + long id = ((DomainBase)SelectedRecibo).Id; + TipoTela? tela = (TipoTela)42; + object[] obj6 = new object[9] + { + SelectedRecibo.Tipo.HasValue ? (ValidationHelper.GetDescription((Enum)(object)SelectedRecibo.Tipo.Value) ?? "") : "-", + null, + null, + null, + null, + null, + null, + null, + null + }; + TipoPagamento? pagamento = SelectedRecibo.Pagamento; + obj6[1] = (pagamento.HasValue ? ValidationHelper.GetDescription((Enum)(object)pagamento.GetValueOrDefault()) : null); + obj6[2] = SelectedRecibo.Valor; + obj6[3] = SelectedRecibo.DataRecibo; + obj6[4] = SelectedRecibo.Pagante; + obj6[5] = SelectedRecibo.DocumentoPagante; + obj6[6] = SelectedRecibo.Recebedor; + obj6[7] = SelectedRecibo.DocumentoRecebedor; + obj6[8] = SelectedRecibo.Referente; + reciboViewModel2.RegistrarAcao(descricao, id, tela, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", obj6)); + } + + private static string GetImage(byte[] bytes, string extensao) + { + try + { + Image val = Image.FromStream((Stream)new MemoryStream(bytes)); + string text = (extensao.ToUpper().Contains("JPG") ? ("data:image/jpeg;base64," + Convert.ToBase64String(bytes, Base64FormattingOptions.None)) : ("data:image/png;base64," + Convert.ToBase64String(bytes, Base64FormattingOptions.None))); + return ""; + } + catch (Exception) + { + return ""; + } + } + + private void WorkOnSelectedRecibo(Recibo value, bool registrar = true) + { + //IL_002e: Unknown result type (might be due to invalid IL or missing references) + //IL_0069: Unknown result type (might be due to invalid IL or missing references) + //IL_0070: Invalid comparison between Unknown and I4 + //IL_01ad: Unknown result type (might be due to invalid IL or missing references) + //IL_00de: Unknown result type (might be due to invalid IL or missing references) + //IL_0113: Unknown result type (might be due to invalid IL or missing references) + CancelRecibo = (Recibo)((value == null || ((DomainBase)value).Id == 0L) ? ((object)CancelRecibo) : ((object)(Recibo)((DomainBase)value).Clone())); + if (value == null || ((DomainBase)value).Id == 0L || (LastAccessId == ((DomainBase)value).Id && (int)LastAccessTela == 42)) + { + return; + } + if (registrar) + { + string descricao = $"ACESSOU RECIBO DE NÚMERO \"{((DomainBase)value).Id}\""; + long id = ((DomainBase)value).Id; + TipoTela? tela = (TipoTela)42; + object[] obj = new object[9] + { + value.Tipo.HasValue ? (ValidationHelper.GetDescription((Enum)(object)value.Tipo.Value) ?? "") : "-", + null, + null, + null, + null, + null, + null, + null, + null + }; + TipoPagamento? pagamento = value.Pagamento; + obj[1] = (pagamento.HasValue ? ValidationHelper.GetDescription((Enum)(object)pagamento.GetValueOrDefault()) : null); + obj[2] = value.Valor; + obj[3] = value.DataRecibo; + obj[4] = value.Pagante; + obj[5] = value.DocumentoPagante; + obj[6] = value.Recebedor; + obj[7] = value.DocumentoRecebedor; + obj[8] = value.Referente; + RegistrarAcao(descricao, id, tela, string.Format("TIPO: {0}\nPAGAMENTO: {1}\nVALOR: {2:c}\nDATA RECIBO: {3:G}\nPAGANTE: {4}, {5}\nRECEBEDOR: {6}, {7}\nREFERENTE: \"{8}\"", obj)); + } + LastAccessId = ((DomainBase)value).Id; + LastAccessTela = (TipoTela)42; + Recibo selectedRecibo = SelectedRecibo; + if (((selectedRecibo != null) ? new long?(((DomainBase)selectedRecibo).Id) : null) != ((DomainBase)value).Id) + { + SelectedRecibo = ((IEnumerable)RecibosFiltrados).FirstOrDefault((Func)((Recibo x) => ((DomainBase)x).Id == ((DomainBase)value).Id)); + } + } +} -- cgit v1.2.3