summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
commit225aa1499e37faf9d38257caabbadc68d78b427e (patch)
tree102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs371
1 files changed, 371 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs
new file mode 100644
index 0000000..abe8a24
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels.Generic/BaseFinanceiroViewModel.cs
@@ -0,0 +1,371 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Forms;
+using Gestor.Application.Componentes;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Financeiro;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Financeiro;
+using MaterialDesignThemes.Wpf;
+using OfxSharpLib;
+using Xceed.Wpf.AvalonDock.Controls;
+
+namespace Gestor.Application.ViewModels.Generic;
+
+public abstract class BaseFinanceiroViewModel : BaseViewModel
+{
+ public AutoCompleteFilterPredicate<object> BancosContasItemFilter => (string searchText, object obj) => ((BancosContas)obj).Descricao.ToUpper().Contains(searchText.ToUpper());
+
+ public AutoCompleteFilterPredicate<object> FornecedorItemFilter => (string searchText, object obj) => (((Fornecedor)obj).Nome != null && ((Fornecedor)obj).Nome.ToUpper().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Documento != null && ((Fornecedor)obj).Documento.ToString().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Telefone1 != null && ((Fornecedor)obj).Telefone1.ToString().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Telefone2 != null && ((Fornecedor)obj).Telefone2.ToString().Contains(searchText.ToUpper())) || (((Fornecedor)obj).Email != null && ((Fornecedor)obj).Email.ToString().Contains(searchText.ToUpper()));
+
+ public AutoCompleteFilterPredicate<object> LancamentoItemFilter => delegate(string searchText, object obj)
+ {
+ //IL_0001: Unknown result type (might be due to invalid IL or missing references)
+ //IL_002e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_000e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0056: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0099: Unknown result type (might be due to invalid IL or missing references)
+ //IL_006b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00dc: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ae: 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)
+ //IL_00e9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0156: Unknown result type (might be due to invalid IL or missing references)
+ //IL_012c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_019e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_016f: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01e3: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01b7: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01fc: Unknown result type (might be due to invalid IL or missing references)
+ if ((((Lancamento)obj).Historico == null || !((Lancamento)obj).Historico.ToUpper().Contains(searchText.ToUpper())) && !((Lancamento)obj).Vencimento.ToString().ToUpper().Contains(searchText.ToUpper()) && (!((Lancamento)obj).Baixa.HasValue || !((Lancamento)obj).Baixa.ToString().ToUpper().Contains(searchText.ToUpper())) && (!((Lancamento)obj).Pagamento.HasValue || !((Lancamento)obj).Pagamento.ToString().ToUpper().Contains(searchText.ToUpper())) && (((Lancamento)obj).Conta == null || !((Lancamento)obj).Conta.Descricao.ToString().ToUpper().Contains(searchText.ToUpper())))
+ {
+ ControleFinanceiro controle = ((Lancamento)obj).Controle;
+ if (((controle != null) ? controle.Historico : null) == null || !((Lancamento)obj).Controle.Historico.ToString().ToUpper().Contains(searchText.ToUpper()))
+ {
+ ControleFinanceiro controle2 = ((Lancamento)obj).Controle;
+ if (((controle2 != null) ? controle2.Plano : null) == null || !((Lancamento)obj).Controle.Plano.Descricao.ToString().ToUpper().Contains(searchText.ToUpper()))
+ {
+ ControleFinanceiro controle3 = ((Lancamento)obj).Controle;
+ if (((controle3 != null) ? controle3.Centro : null) == null || !((Lancamento)obj).Controle.Centro.Descricao.ToString().ToUpper().Contains(searchText.ToUpper()))
+ {
+ ControleFinanceiro controle4 = ((Lancamento)obj).Controle;
+ if (((controle4 != null) ? controle4.Fornecedor : null) != null)
+ {
+ return ((Lancamento)obj).Controle.Fornecedor.Nome.ToString().ToUpper().Contains(searchText.ToUpper());
+ }
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ };
+
+ public AutoCompleteFilterPredicate<object> PlanoItemFilter => (string searchText, object obj) => ((Plano)obj).Descricao.ToUpper().Contains(searchText.ToUpper()) || ((Plano)obj).Descricao.ToString().Contains(searchText.ToUpper());
+
+ public AutoCompleteFilterPredicate<object> PlanosItemFilter => (string searchText, object obj) => ((Planos)obj).Descricao.ToUpper().Contains(searchText.ToUpper()) || ((Planos)obj).Descricao.ToString().Contains(searchText.ToUpper());
+
+ public AutoCompleteFilterPredicate<object> BancoItemFilter => (string searchText, object obj) => ((Banco)obj).Nome.ToUpper().Contains(searchText.ToUpper());
+
+ internal async Task<List<BancosContas>> BuscarBancosContas(string value)
+ {
+ return await Task.Run(() => new BaseServico().BuscarBancosContas(value));
+ }
+
+ internal async Task<List<Fornecedor>> BuscarFornecedor(string value)
+ {
+ return await Task.Run(() => new BaseServico().BuscarFornecedor(value));
+ }
+
+ internal async Task<List<Fornecedor>> BuscarFornecedorAtivo(string value)
+ {
+ return await Task.Run(() => new BaseServico().BuscarFornecedor(value, ativo: true));
+ }
+
+ internal async Task<Transferencia> ShowTransferencia(Transferencia transferencia)
+ {
+ DialogHost val = Extentions.FindVisualChildren<DialogHost>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).FirstOrDefault();
+ DialogTransferencia dialogControl = new DialogTransferencia(transferencia);
+ return await ExecuteRunExtendedDialogTransferencia((UserControl)(object)dialogControl, (val != null) ? val.Identifier.ToString() : "RootDialog");
+ }
+
+ public async Task<Transferencia> ExecuteRunExtendedDialogTransferencia(UserControl dialogControl, string hostName)
+ {
+ Extentions.FindVisualChildren<WebEditor>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).ToList().ForEach(delegate(WebEditor x)
+ {
+ ((UIElement)x).Visibility = (Visibility)2;
+ });
+ object obj = await DialogHost.Show((object)dialogControl, (object)hostName, new DialogOpenedEventHandler(base.ExtendedOpenedEventHandler), new DialogClosingEventHandler(base.ExtendedClosingEventHandler));
+ if (obj is bool)
+ {
+ return null;
+ }
+ return (Transferencia)obj;
+ }
+
+ internal async Task<Lancamento> ShowVinculo(FinanceiroViewModel viewModel)
+ {
+ DialogHost val = Extentions.FindVisualChildren<DialogHost>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).FirstOrDefault();
+ VincularLancamentoDialog dialogControl = new VincularLancamentoDialog(viewModel);
+ return await ExecuteRunExtendedDialogVinculo((UserControl)(object)dialogControl, (val != null) ? val.Identifier.ToString() : "RootDialog");
+ }
+
+ public async Task<Lancamento> ExecuteRunExtendedDialogVinculo(UserControl dialogControl, string hostName)
+ {
+ Extentions.FindVisualChildren<WebEditor>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).ToList().ForEach(delegate(WebEditor x)
+ {
+ ((UIElement)x).Visibility = (Visibility)2;
+ });
+ object obj = await DialogHost.Show((object)dialogControl, (object)hostName, new DialogOpenedEventHandler(base.ExtendedOpenedEventHandler), new DialogClosingEventHandler(base.ExtendedClosingEventHandler));
+ if (obj is bool)
+ {
+ return null;
+ }
+ return (Lancamento)obj;
+ }
+
+ internal async Task<BancosContas> ShowContas(List<BancosContas> contas)
+ {
+ DialogHost val = Extentions.FindVisualChildren<DialogHost>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).FirstOrDefault();
+ ContasDialog dialogControl = new ContasDialog(contas);
+ return await ExecuteRunExtendedDialogContas((UserControl)(object)dialogControl, (val != null) ? val.Identifier.ToString() : "RootDialog");
+ }
+
+ public async Task<BancosContas> ExecuteRunExtendedDialogContas(UserControl dialogControl, string hostName)
+ {
+ Extentions.FindVisualChildren<WebEditor>((DependencyObject)(object)((IEnumerable)Application.Current.Windows).OfType<Window>().SingleOrDefault((Func<Window, bool>)((Window x) => x.IsActive))).ToList().ForEach(delegate(WebEditor x)
+ {
+ ((UIElement)x).Visibility = (Visibility)2;
+ });
+ object obj = await DialogHost.Show((object)dialogControl, (object)hostName, new DialogOpenedEventHandler(base.ExtendedOpenedEventHandler), new DialogClosingEventHandler(base.ExtendedClosingEventHandler));
+ if (obj is bool)
+ {
+ return null;
+ }
+ return (BancosContas)obj;
+ }
+
+ public Encoding GetEncoding(string filename)
+ {
+ byte[] array = new byte[4];
+ using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
+ {
+ fileStream.Read(array, 0, 4);
+ }
+ if (array[0] == 43 && array[1] == 47 && array[2] == 118)
+ {
+ return Encoding.UTF7;
+ }
+ if (array[0] == 239 && array[1] == 187 && array[2] == 191)
+ {
+ return Encoding.UTF8;
+ }
+ if (array[0] == byte.MaxValue && array[1] == 254 && array[2] == 0 && array[3] == 0)
+ {
+ return Encoding.UTF32;
+ }
+ if (array[0] == byte.MaxValue && array[1] == 254)
+ {
+ return Encoding.Unicode;
+ }
+ if (array[0] == 254 && array[1] == byte.MaxValue)
+ {
+ return Encoding.BigEndianUnicode;
+ }
+ if (array[0] == 0 && array[1] == 0 && array[2] == 254 && array[3] == byte.MaxValue)
+ {
+ return new UTF32Encoding(bigEndian: true, byteOrderMark: true);
+ }
+ return Encoding.ASCII;
+ }
+
+ public async Task<List<OfxDocument>> ImportarOfx()
+ {
+ List<OfxDocument> ofxDocuments = new List<OfxDocument>();
+ bool error = false;
+ List<string> files = new List<string>();
+ OpenFileDialog val = new OpenFileDialog();
+ try
+ {
+ val.Multiselect = true;
+ ((FileDialog)val).Filter = "Arquivos OFX|*.ofx";
+ ((FileDialog)val).InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
+ if (1 != (int)((CommonDialog)val).ShowDialog())
+ {
+ return null;
+ }
+ files.AddRange(((FileDialog)val).FileNames);
+ }
+ finally
+ {
+ ((IDisposable)val)?.Dispose();
+ }
+ await Task.Run(delegate
+ {
+ //IL_000e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0018: Expected O, but got Unknown
+ OfxDocumentParser parser = new OfxDocumentParser();
+ files.ForEach(delegate(string x)
+ {
+ try
+ {
+ string text = DateTime.Now.Date.ToString("yyyyMMddHHmmss");
+ string text2 = DetectEncodingAndRead(x).Replace("<DTASOF>00000000", "<DTASOF>" + text).Replace("<DTSERVER>00000000000000", "<DTSERVER>" + text).Replace(",", ".")
+ .Replace("<REFNUM> </REFNUM>", "<REFNUM>.</REFNUM>");
+ if (text2.Contains("<FID>336</FID>") && !text2.Contains("<LEDGERBAL>"))
+ {
+ text2 = text2.Replace("UTF - 8", "USASCII").Replace("</BANKTRANLIST>", "</BANKTRANLIST>\r\n<LEDGERBAL>\r\n<BALAMT>0\r\n<DTASOF>00000000\r\n</LEDGERBAL>").Replace("<DTASOF>00000000", "<DTASOF>" + text)
+ .Replace(": ", ":")
+ .Replace(" ", "")
+ .Replace("<REFNUM/>", "<REFNUM>0");
+ }
+ if (text2.Contains("<FID>0403</FID>") && !text2.Contains("CHARSET:1252") && text2.Contains("ENCODING:UTF-8"))
+ {
+ text2 = text2.Replace("UTF-8", "USASCII\nCHARSET:1252").Replace("<DTASOF>00000000", "<DTASOF>" + text).Replace("[0:GMT]", "")
+ .Replace(": ", ":")
+ .Replace(" ", "");
+ }
+ if (text2.Contains("<FID>260"))
+ {
+ text2 = text2.Replace("UTF-8", "USASCII").Replace("CHARSET:NONE", "CHARSET:1252");
+ }
+ if (text2.Contains("<MEMO></MEMO>"))
+ {
+ text2 = text2.Replace("<MEMO></MEMO>", "<MEMO>SEM INFORMAÇÃO</MEMO>");
+ }
+ if (Regex.IsMatch(text2, "<NAME>\\s*</NAME>"))
+ {
+ text2 = text2.Replace("<NAME>\n</NAME>", "<NAME>SEM NOME</NAME>").Replace("<NAME></NAME>", "<NAME>SEM NOME</NAME>");
+ }
+ OfxDocument item = parser.Import(text2);
+ ofxDocuments.Add(item);
+ }
+ catch (Exception)
+ {
+ error = true;
+ }
+ });
+ });
+ if (error)
+ {
+ await ShowMessage("HOUVE PROBLEMAS AO IMPORTAR O OFX, BAIXE-O NOVAMENTE COM UM PERÍODO MENOR.");
+ }
+ return ofxDocuments;
+ }
+
+ private string DetectEncodingAndRead(string arquivo)
+ {
+ return File.ReadAllText(arquivo, DetectTextFileEncoding(arquivo));
+ }
+
+ public static Encoding DetectTextFileEncoding(string filePath)
+ {
+ byte[] array;
+ using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
+ {
+ int num = (int)Math.Min(fileStream.Length, 4096L);
+ array = new byte[num];
+ fileStream.Read(array, 0, num);
+ }
+ if (array.Length >= 2)
+ {
+ if (array.Length >= 3 && array[0] == 239 && array[1] == 187 && array[2] == 191)
+ {
+ return Encoding.UTF8;
+ }
+ if (array[0] == byte.MaxValue && array[1] == 254)
+ {
+ return Encoding.Unicode;
+ }
+ if (array[0] == 254 && array[1] == byte.MaxValue)
+ {
+ return Encoding.BigEndianUnicode;
+ }
+ if (array.Length >= 4 && array[0] == byte.MaxValue && array[1] == 254 && array[2] == 0 && array[3] == 0)
+ {
+ return Encoding.UTF32;
+ }
+ if (array.Length >= 4 && array[0] == 0 && array[1] == 0 && array[2] == 254 && array[3] == byte.MaxValue)
+ {
+ return new UTF32Encoding(bigEndian: true, byteOrderMark: true);
+ }
+ }
+ bool flag = true;
+ int num2 = 0;
+ int num3 = 0;
+ for (int i = 0; i < array.Length; i++)
+ {
+ if (array[i] <= 127)
+ {
+ num3++;
+ continue;
+ }
+ if (array[i] >= 194 && array[i] <= 223 && i + 1 < array.Length && array[i + 1] >= 128 && array[i + 1] <= 191)
+ {
+ num2++;
+ i++;
+ continue;
+ }
+ if (array[i] >= 224 && array[i] <= 239 && i + 2 < array.Length && array[i + 1] >= 128 && array[i + 1] <= 191 && array[i + 2] >= 128 && array[i + 2] <= 191)
+ {
+ num2++;
+ i += 2;
+ continue;
+ }
+ if (array[i] >= 240 && array[i] <= 244 && i + 3 < array.Length && array[i + 1] >= 128 && array[i + 1] <= 191 && array[i + 2] >= 128 && array[i + 2] <= 191 && array[i + 3] >= 128 && array[i + 3] <= 191)
+ {
+ num2++;
+ i += 3;
+ continue;
+ }
+ flag = false;
+ break;
+ }
+ int num4 = 0;
+ for (int j = 0; j < array.Length - 1; j += 2)
+ {
+ if (array[j] == 0 || array[j + 1] == 0)
+ {
+ num4++;
+ }
+ }
+ if (flag && num2 > 0)
+ {
+ return Encoding.UTF8;
+ }
+ if ((double)num3 > (double)array.Length * 0.95)
+ {
+ return Encoding.ASCII;
+ }
+ if ((double)num4 > (double)array.Length * 0.4)
+ {
+ int num5 = 0;
+ int num6 = 0;
+ for (int k = 0; k < array.Length - 1; k += 2)
+ {
+ if (array[k] == 0 && array[k + 1] != 0)
+ {
+ num6++;
+ }
+ if (array[k] != 0 && array[k + 1] == 0)
+ {
+ num5++;
+ }
+ }
+ if (num5 > num6)
+ {
+ return Encoding.Unicode;
+ }
+ return Encoding.BigEndianUnicode;
+ }
+ return Encoding.GetEncoding(1252);
+ }
+}