summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.cs
blob: 06cd65657cf9353d663e65103880ec92df51d7ec (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Assinador.Infrastructure.Helpers;
using Gestor.Application.Servicos.Ferramentas;
using Gestor.Application.Servicos.Generic;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;

namespace Gestor.Application.ViewModels.Drawer;

public class AdiantamentoViewModel : BaseSegurosViewModel
{
	private readonly AdiantamentoServico _servico;

	private readonly Vendedor _selectedVendedor;

	private bool _carregando;

	private ObservableCollection<Adiantamento> _adiantamento = new ObservableCollection<Adiantamento>();

	private Adiantamento _selectedAdiantamento = new Adiantamento();

	private bool _logEnabled;

	public Adiantamento CancelAdiantamento;

	public bool Carregando
	{
		get
		{
			return _carregando;
		}
		set
		{
			_carregando = value;
			base.IsEnabled = !value;
			base.EnableMenu = !value;
			OnPropertyChanged("Carregando");
		}
	}

	public ObservableCollection<Adiantamento> Adiantamento
	{
		get
		{
			return _adiantamento;
		}
		set
		{
			_adiantamento = value;
			OnPropertyChanged("Adiantamento");
		}
	}

	public Adiantamento SelectedAdiantamento
	{
		get
		{
			return _selectedAdiantamento;
		}
		set
		{
			_selectedAdiantamento = value;
			CancelAdiantamento = ((value != null && ((DomainBase)value).Id > 0) ? value : CancelAdiantamento);
			VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null);
			OnPropertyChanged("SelectedAdiantamento");
		}
	}

	public bool LogEnabled
	{
		get
		{
			return _logEnabled;
		}
		set
		{
			_logEnabled = value;
			OnPropertyChanged("LogEnabled");
		}
	}

	public AdiantamentoViewModel(Vendedor vendedor)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		_servico = new AdiantamentoServico();
		Seleciona(vendedor);
		_selectedVendedor = vendedor;
	}

	private async void Seleciona(Vendedor vendedor)
	{
		Loading(isLoading: true);
		await PermissaoTela((TipoTela)15);
		await SelecionaAdiantamento(vendedor);
		Loading(isLoading: false);
	}

	public void SelecionaAdiantamento(Adiantamento adiantamento)
	{
		SelectedAdiantamento = adiantamento;
	}

	private async Task SelecionaAdiantamento(Vendedor vendedor)
	{
		Carregando = true;
		List<Adiantamento> list = (from x in await new BaseServico().BuscarAdiantamentoAsync(vendedor)
			orderby x.Pago, x.Valor
			select x).ToList();
		Adiantamento = new ObservableCollection<Adiantamento>(list);
		if (Adiantamento.Count > 0)
		{
			SelecionaAdiantamento(Adiantamento.First());
			LogEnabled = true;
		}
		else
		{
			SelectedAdiantamento = new Adiantamento();
			LogEnabled = false;
			Alterar(alterar: false);
			VerificarEnables(((DomainBase)SelectedAdiantamento).Id);
			base.EnableMenu = false;
		}
		Carregando = false;
	}

	public void Incluir()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		Adiantamento selectedAdiantamento = new Adiantamento();
		SelectedAdiantamento = selectedAdiantamento;
		Alterar(alterar: true);
	}

	public async Task<List<KeyValuePair<string, string>>> Salvar()
	{
		if (string.IsNullOrWhiteSpace(SelectedAdiantamento.Historico))
		{
			return new List<KeyValuePair<string, string>>
			{
				new KeyValuePair<string, string>("Historico|HISTÓRICO", "OBRIGATÓRIO")
			};
		}
		SelectedAdiantamento.Vendedor = _selectedVendedor;
		string acao = ((((DomainBase)SelectedAdiantamento).Id == 0L) ? "INCLUIU" : "ALTEROU");
		Adiantamento value = await _servico.Save(SelectedAdiantamento);
		if (!_servico.Sucesso)
		{
			return null;
		}
		RegistrarAcao(acao + " ADIANTAMENTO DO VENDEDOR \"" + value.Vendedor.Nome + "\"", ((DomainBase)value).Id, (TipoTela)36, string.Format("ID: {0}\nDATA: {1}\nVALOR: {2:c}\nTIPO PAGAMENTO: {3}\nPAGO: {4}", ((DomainBase)value).Id, (!value.Data.HasValue) ? "-" : $"{value.Data:d}", value.Valor, Functions.GetDescription((Enum)(object)value.TipoPagamento), value.Pago ? "SIM" : "NÃO"));
		if (Adiantamento.Any((Adiantamento x) => ((DomainBase)x).Id == ((DomainBase)value).Id))
		{
			DomainBase.Copy<Adiantamento, Adiantamento>(Adiantamento.First((Adiantamento x) => ((DomainBase)x).Id == ((DomainBase)value).Id), value);
		}
		else
		{
			Adiantamento.Add(value);
		}
		Adiantamento = new ObservableCollection<Adiantamento>(Adiantamento);
		SelectedAdiantamento = Adiantamento.First((Adiantamento x) => ((DomainBase)x).Id == ((DomainBase)value).Id);
		LogEnabled = true;
		Alterar(alterar: false);
		return null;
	}

	public void CancelarAlteracao()
	{
		Carregando = true;
		if (CancelAdiantamento != null && Adiantamento.Any((Adiantamento x) => ((DomainBase)x).Id == ((DomainBase)CancelAdiantamento).Id))
		{
			DomainBase.Copy<Adiantamento, Adiantamento>(Adiantamento.First((Adiantamento x) => ((DomainBase)x).Id == ((DomainBase)CancelAdiantamento).Id), CancelAdiantamento);
			SelectedAdiantamento = Adiantamento.First((Adiantamento x) => ((DomainBase)x).Id == ((DomainBase)CancelAdiantamento).Id);
		}
		Alterar(alterar: false);
		Carregando = false;
	}

	public async Task<bool> Excluir()
	{
		if (SelectedAdiantamento == null || ((DomainBase)SelectedAdiantamento).Id == 0L)
		{
			return false;
		}
		if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO")))
		{
			return false;
		}
		Carregando = true;
		if (!(await _servico.Delete(SelectedAdiantamento)))
		{
			return false;
		}
		RegistrarAcao("EXCLUIU O ADIANTAMENTO DO VENDEDOR \"" + SelectedAdiantamento.Vendedor.Nome + "\"", ((DomainBase)SelectedAdiantamento).Id, (TipoTela)36, string.Format("ID: {0}\nDATA: {1}\nVALOR: {2:c}\nTIPO PAGAMENTO: {3}\nPAGO: {4}", ((DomainBase)SelectedAdiantamento).Id, (!SelectedAdiantamento.Data.HasValue) ? "-" : $"{SelectedAdiantamento.Data:d}", SelectedAdiantamento.Valor, Functions.GetDescription((Enum)(object)SelectedAdiantamento.TipoPagamento), SelectedAdiantamento.Pago ? "SIM" : "NÃO"));
		int num = Adiantamento.IndexOf(SelectedAdiantamento);
		Adiantamento.Remove(SelectedAdiantamento);
		Adiantamento.Remove(SelectedAdiantamento);
		Adiantamento = new ObservableCollection<Adiantamento>(Adiantamento);
		if (Adiantamento.Count > 0)
		{
			SelectedAdiantamento = ((num < Adiantamento.Count) ? Adiantamento.ElementAt(num) : Adiantamento.Last());
			LogEnabled = true;
		}
		else
		{
			SelectedAdiantamento = new Adiantamento();
			Alterar(alterar: false);
			base.EnableMenu = false;
			LogEnabled = false;
		}
		if (Adiantamento.Count > 0)
		{
			SelecionaAdiantamento((num < Adiantamento.Count) ? Adiantamento.ElementAt(num) : Adiantamento.Last());
			LogEnabled = true;
		}
		else
		{
			SelectedAdiantamento = new Adiantamento();
			LogEnabled = false;
			Alterar(alterar: false);
		}
		Carregando = false;
		return true;
	}

	public async Task CarregarAdiantamento(int index)
	{
		Carregando = true;
		Adiantamento = new ObservableCollection<Adiantamento>(await _servico.BuscarAdiantamentos(((DomainBase)_selectedVendedor).Id, index != 0));
		if (Adiantamento != null && Adiantamento.Count > 0)
		{
			SelectedAdiantamento = Adiantamento.First();
			LogEnabled = true;
		}
		else
		{
			LogEnabled = false;
		}
		Carregando = false;
	}
}