summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.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.Drawer/AdiantamentoViewModel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.cs248
1 files changed, 248 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.cs
new file mode 100644
index 0000000..06cd656
--- /dev/null
+++ b/Decompiler/Gestor.Application.ViewModels.Drawer/AdiantamentoViewModel.cs
@@ -0,0 +1,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;
+ }
+}