summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Relatorios/SinteticoViewModel.cs
blob: c3adb1d7d5078dfe6a07be11bd74e01cddcd3700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using ClosedXML.Excel;
using Gestor.Application.Componentes;
using Gestor.Application.Helpers;
using Gestor.Application.Model;
using Gestor.Application.ViewModels.Generic;
using Gestor.Common.Helpers;
using Gestor.Model.Attributes;
using Gestor.Model.Common;
using Gestor.Model.Domain.Configuracoes;
using Gestor.Model.Domain.Relatorios;
using LiveCharts;
using LiveCharts.Definitions.Series;
using LiveCharts.Helpers;
using LiveCharts.Wpf;
using NReco.PdfGenerator;

namespace Gestor.Application.ViewModels.Relatorios;

public class SinteticoViewModel : BaseSegurosViewModel
{
	private Visibility _unicaPaginaVisibility = (Visibility)2;

	private Geometry _maximizeRestore = Geometry.Parse((string)Application.Current.Resources[(object)"Restore"]);

	private ObservableCollection<SinteticoSource> _series;

	private string _titulotela = $"RELATÓRIO SINTÉTICO | VERSÃO GESTOR {ApplicationHelper.Versao}";

	public Visibility UnicaPaginaVisibility
	{
		get
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return _unicaPaginaVisibility;
		}
		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)
			_unicaPaginaVisibility = value;
			OnPropertyChanged("UnicaPaginaVisibility");
		}
	}

	public string Relatorio { get; set; }

	public Geometry MaximizeRestore
	{
		get
		{
			return _maximizeRestore;
		}
		set
		{
			_maximizeRestore = value;
			OnPropertyChanged("MaximizeRestore");
		}
	}

	public ObservableCollection<SinteticoSource> Series
	{
		get
		{
			return _series;
		}
		set
		{
			_series = value;
			OnPropertyChanged("Series");
		}
	}

	public string Titulotela
	{
		get
		{
			return _titulotela;
		}
		set
		{
			_titulotela = value;
			OnPropertyChanged("Titulotela");
		}
	}

	public SinteticoViewModel(List<Sintetico> sintetico, string relatorio)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		Relatorio = relatorio;
		GerarSintetico(sintetico);
	}

	private void GerarSintetico(List<Sintetico> sintetico)
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Expected O, but got Unknown
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_0451: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Expected O, but got Unknown
		//IL_046a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0477: Expected O, but got Unknown
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Expected O, but got Unknown
		//IL_071b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0720: Unknown result type (might be due to invalid IL or missing references)
		//IL_072b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0733: Unknown result type (might be due to invalid IL or missing references)
		//IL_073e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0746: Unknown result type (might be due to invalid IL or missing references)
		//IL_0589: Unknown result type (might be due to invalid IL or missing references)
		//IL_058e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0599: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_076e: Unknown result type (might be due to invalid IL or missing references)
		//IL_077e: Expected O, but got Unknown
		//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05dd: Expected O, but got Unknown
		UnicaPaginaVisibility = (Visibility)((!(Relatorio == "RELATÓRIO DE FECHAMENTO")) ? 2 : 0);
		Series = new ObservableCollection<SinteticoSource>();
		PropertyInfo[] properties = ((object)sintetico.First()).GetType().GetProperties();
		foreach (PropertyInfo parentProperty in properties)
		{
			if (parentProperty.Name == "ValidationEvent" || parentProperty.Name == "Agrupamento" || sintetico.All((Sintetico s) => ((object)s).GetType().GetProperty(parentProperty.Name)?.GetValue(s, null) == null))
			{
				continue;
			}
			object obj = parentProperty.GetCustomAttributes(typeof(DescriptionAttribute), inherit: true).FirstOrDefault();
			if (obj == null)
			{
				continue;
			}
			string description = ((DescriptionAttribute)obj).Description;
			SinteticoSource sinteticoSource = new SinteticoSource
			{
				Titulo = description,
				Colecao = new SeriesCollection(),
				Lista = new ObservableCollection<ValorSintetico>()
			};
			object obj2 = parentProperty.GetCustomAttributes(typeof(TipoAttribute), inherit: true).FirstOrDefault();
			string text = "";
			if (obj2 != null)
			{
				text = ((TipoAttribute)obj2).Description;
			}
			sintetico = sintetico.OrderByDescending((Sintetico x) => parentProperty.GetValue(x, null)).ToList();
			foreach (Sintetico x2 in sintetico)
			{
				bool flag = false;
				PieSeries val = new PieSeries
				{
					Title = x2.Agrupamento,
					DataLabels = false
				};
				IChartValues values;
				if (!(text == "PERCENTUAL"))
				{
					if (!(text == "VALOR"))
					{
						flag = (int)parentProperty.GetValue(x2) < 0;
						ChartValues<int> obj3 = new ChartValues<int>();
						((NoisyCollection<int>)(object)obj3).Add(Math.Abs((int)parentProperty.GetValue(x2)));
						values = (IChartValues)(object)obj3;
						sinteticoSource.Lista.Add(new ValorSintetico
						{
							Indice = x2.Agrupamento + (flag ? " (-)" : ""),
							Valor = decimal.Parse(parentProperty.GetValue(x2).ToString()),
							Formato = text,
							Sinal = (Sinal)(flag ? 1 : 0),
							NomeRelatorio = description
						});
						((Series)val).LabelPoint = (ChartPoint chartPoint) => ((int)parentProperty.GetValue(x2)).ToString("n");
					}
					else
					{
						flag = (decimal)parentProperty.GetValue(x2) < 0m;
						ChartValues<decimal> obj4 = new ChartValues<decimal>();
						((NoisyCollection<decimal>)(object)obj4).Add(Math.Abs((decimal)parentProperty.GetValue(x2)));
						values = (IChartValues)(object)obj4;
						sinteticoSource.Lista.Add(new ValorSintetico
						{
							Indice = x2.Agrupamento + (flag ? " (-)" : ""),
							Valor = Math.Round((decimal)parentProperty.GetValue(x2), 2),
							Formato = text,
							Unidate = "R$",
							Sinal = (Sinal)(flag ? 1 : 0),
							NomeRelatorio = description
						});
						((Series)val).LabelPoint = (ChartPoint chartPoint) => ((decimal)parentProperty.GetValue(x2)).ToString("n2");
					}
				}
				else
				{
					flag = (decimal)parentProperty.GetValue(x2) < 0m;
					ChartValues<decimal> obj5 = new ChartValues<decimal>();
					((NoisyCollection<decimal>)(object)obj5).Add(Math.Abs((decimal)parentProperty.GetValue(x2)));
					values = (IChartValues)(object)obj5;
					sinteticoSource.Lista.Add(new ValorSintetico
					{
						Indice = x2.Agrupamento + (flag ? " (-)" : ""),
						Valor = Math.Round((decimal)parentProperty.GetValue(x2) * 0.01m, 2),
						Unidate = "%",
						Sinal = (Sinal)(flag ? 1 : 0),
						NomeRelatorio = description
					});
					((Series)val).LabelPoint = (ChartPoint chartPoint) => ((decimal)parentProperty.GetValue(x2)).ToString("n2");
				}
				((Series)val).Values = values;
				((NoisyCollection<ISeriesView>)(object)sinteticoSource.Colecao).Add((ISeriesView)(object)val);
			}
			if (obj2 != null && !(text == "PERCENTUAL"))
			{
				if (!(text == "VALOR"))
				{
					if (!Relatorio.Equals("RELATÓRIO DE FECHAMENTO"))
					{
						int num = sintetico.Sum((Sintetico x) => (int)parentProperty.GetValue(x, null));
						if (num != 0)
						{
							foreach (ValorSintetico listum in sinteticoSource.Lista)
							{
								listum.Porcentagem = (100m * listum.Valor / (decimal)num).ToString("F") + "%";
							}
						}
						sinteticoSource.Lista.Add(new ValorSintetico
						{
							Indice = "TOTAL",
							Valor = num,
							Formato = text,
							Sinal = (Sinal)(sintetico.Sum((Sintetico x) => (int)parentProperty.GetValue(x, null)) < 0),
							Porcentagem = "100%"
						});
					}
					else
					{
						int num2 = sintetico.Sum((Sintetico x) => (int)parentProperty.GetValue(x, null));
						if (num2 != 0)
						{
							foreach (ValorSintetico listum2 in sinteticoSource.Lista)
							{
								listum2.Porcentagem = (100m * listum2.Valor / (decimal)num2).ToString("F") + "%";
							}
						}
					}
				}
				else if (!Relatorio.Equals("RELATÓRIO DE FECHAMENTO"))
				{
					decimal num3 = Math.Round(sintetico.Sum((Sintetico x) => (decimal)parentProperty.GetValue(x, null)), 2);
					if (num3 != 0m)
					{
						foreach (ValorSintetico listum3 in sinteticoSource.Lista)
						{
							listum3.Porcentagem = (100m * listum3.Valor / num3).ToString("F") + "%";
						}
					}
					sinteticoSource.Lista.Add(new ValorSintetico
					{
						Indice = "TOTAL",
						Valor = num3,
						Unidate = "R$",
						Formato = text,
						Sinal = (Sinal)((sintetico.Sum((Sintetico x) => (decimal)parentProperty.GetValue(x, null)) < 0m) ? 1 : 0),
						Porcentagem = "100%"
					});
				}
				else
				{
					decimal num4 = Math.Round(sintetico.Sum((Sintetico x) => (decimal)parentProperty.GetValue(x, null)), 2);
					if (num4 != 0m)
					{
						foreach (ValorSintetico listum4 in sinteticoSource.Lista)
						{
							listum4.Porcentagem = (100m * listum4.Valor / num4).ToString("F") + "%";
						}
					}
				}
			}
			Series.Add(sinteticoSource);
		}
	}

	public async Task Print(SinteticoSource sintetico)
	{
		string grafico = Funcoes.GerarGrafico(sintetico.Lista.ToList());
		string dados = await Funcoes.GenerateTable(GerarRelacao(sintetico.Lista.ToList()), new List<string>(), grafico: true);
		string value = Funcoes.ExportarHtml(new TipoRelatorio
		{
			Nome = sintetico.Titulo,
			Inicio = (sintetico.DateStart ?? DateTime.MinValue),
			Fim = (sintetico.DateFinal ?? DateTime.MinValue)
		}, dados, "60", "landscape", search: false, grafico);
		string tempPath = Path.GetTempPath();
		string text = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, new Regex("[" + Regex.Escape(new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars())) + "]").Replace(Relatorio, ""), Funcoes.GetNetworkTime());
		StreamWriter streamWriter = new StreamWriter(text, append: true, Encoding.UTF8);
		streamWriter.Write(value);
		streamWriter.Close();
		Process.Start(text);
	}

	public async Task PrintUnica(SinteticoSource sintetico)
	{
		List<List<ValorSintetico>> list = new List<List<ValorSintetico>>();
		foreach (SinteticoSource item in Series)
		{
			list.Add(item.Lista.ToList());
		}
		string grafico = Funcoes.GerarGraficoUnico(list);
		string dados = await Funcoes.GenerateMultipleTable(GerarRelacao(list), new List<string>(), grafico: true);
		string value = Funcoes.ExportarMultipleHtml(new TipoRelatorio
		{
			Nome = "RELATÓRIOS",
			Inicio = (sintetico.DateStart ?? DateTime.MinValue),
			Fim = (sintetico.DateFinal ?? DateTime.MinValue)
		}, dados, "60", "landscape", search: false, grafico);
		string tempPath = Path.GetTempPath();
		string text = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, new Regex("[" + Regex.Escape(new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars())) + "]").Replace(Relatorio, ""), Funcoes.GetNetworkTime());
		StreamWriter streamWriter = new StreamWriter(text, append: true, Encoding.UTF8);
		streamWriter.Write(value);
		streamWriter.Close();
		Process.Start(text);
	}

	private static List<Listagem> GerarRelacao(List<ValorSintetico> lista)
	{
		return ((IEnumerable<ValorSintetico>)lista).Select((Func<ValorSintetico, Listagem>)((ValorSintetico x) => new Listagem
		{
			Agrupamento = x.Indice,
			Valor = ((x.Formato == "VALOR") ? x.Valor.ToString("c2") : ((x.Formato == "PERCENTUAL") ? x.Valor.ToString("p2") : x.Valor.ToString(new CultureInfo("pt-BR")))),
			NomeRelatorio = x.NomeRelatorio
		})).ToList();
	}

	private static List<List<Listagem>> GerarRelacao(List<List<ValorSintetico>> listas)
	{
		List<List<Listagem>> list = new List<List<Listagem>>();
		foreach (List<ValorSintetico> lista in listas)
		{
			list.Add(GerarRelacao(lista));
		}
		return list;
	}

	public async Task GerarPdf(SinteticoSource sintetico)
	{
		string dados = await Funcoes.GenerateTable(GerarRelacao(sintetico.Lista.ToList()), new List<string>());
		string text = Funcoes.ExportarHtml(new TipoRelatorio
		{
			Nome = sintetico.Titulo,
			Inicio = DateTime.MinValue,
			Fim = DateTime.MinValue
		}, dados);
		NRecoHtmlToPdfConverter nRecoHtmlToPdfConverter = new NRecoHtmlToPdfConverter();
		((HtmlToPdfConverter)nRecoHtmlToPdfConverter).Orientation = (PageOrientation)1;
		((HtmlToPdfConverter)nRecoHtmlToPdfConverter).Zoom = 0.5f;
		byte[] bytes = ((HtmlToPdfConverter)nRecoHtmlToPdfConverter).GeneratePdf(text);
		SaveFileDialog sfd = new SaveFileDialog();
		try
		{
			((FileDialog)sfd).Filter = "All Files|*.*";
			((FileDialog)sfd).FileName = $"RELATORIO FINANCEIRO_{Funcoes.GetNetworkTime():ddMMyyyyhhmmss}";
			if (1 != (int)((CommonDialog)sfd).ShowDialog())
			{
				return;
			}
			if (File.Exists(((FileDialog)sfd).FileName + ".pdf"))
			{
				await ShowMessage("JÁ EXISTE UM ARQUIVO COM O NOME DE " + ((FileDialog)sfd).FileName + ".pdf NA PASTA SELECIONADA. " + Environment.NewLine + "TENTE NOVAMENTE EM OUTRA PASTA.");
				return;
			}
			File.WriteAllBytes(((FileDialog)sfd).FileName + ".pdf", bytes);
			Process.Start(((FileDialog)sfd).FileName + ".pdf");
		}
		finally
		{
			((IDisposable)sfd)?.Dispose();
		}
	}

	public async Task GerarExcel(SinteticoSource sintetico)
	{
		List<Listagem> analitico = GerarRelacao(sintetico.Lista.ToList());
		string text = "";
		string fileName;
		if (Recursos.Configuracoes.Any((ConfiguracaoSistema x) => (int)x.Configuracao == 41))
		{
			FolderBrowserDialog val = new FolderBrowserDialog();
			try
			{
				if (1 != (int)((CommonDialog)val).ShowDialog())
				{
					return;
				}
				text = val.SelectedPath + "\\";
				Directory.CreateDirectory(text);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
			fileName = text + "SINTETICO " + Functions.GetNetworkTime().Date.ToShortDateString().Replace("/", "") + ".xlsx";
		}
		else
		{
			text = Path.GetTempPath();
			fileName = $"{text}{Guid.NewGuid()}.xlsx";
		}
		(await Funcoes.GerarXls(new XLWorkbook(), "SINTÉTICO", analitico)).SaveAs(fileName);
		Process.Start(fileName);
	}
}