summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:35:25 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:35:25 +0000
commit674ca83ba9243a9e95a7568c797668dab6aee26a (patch)
tree4a905b3fb1d827665a34d63f67bc5559f8e7235b /Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs
downloadgestor-674ca83ba9243a9e95a7568c797668dab6aee26a.tar.gz
gestor-674ca83ba9243a9e95a7568c797668dab6aee26a.zip
feat: upload files
Diffstat (limited to 'Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs')
-rw-r--r--Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs484
1 files changed, 484 insertions, 0 deletions
diff --git a/Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs b/Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs
new file mode 100644
index 0000000..e2ec7d5
--- /dev/null
+++ b/Gestor.Application/ViewModels/Drawer/ImpostoViewModel.cs
@@ -0,0 +1,484 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Ferramentas;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Configuracoes;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.ViewModels.Drawer
+{
+ public class ImpostoViewModel : BaseViewModel
+ {
+ private bool _carregando;
+
+ private bool _apelido;
+
+ public int Tipo;
+
+ private List<Seguradora> _seguradoras;
+
+ private List<Ramo> _ramos;
+
+ private ObservableCollection<Imposto> _impostos = new ObservableCollection<Imposto>();
+
+ private Imposto _selectedImposto = new Imposto();
+
+ private Ramo _selectedRamo = new Ramo();
+
+ private Seguradora _selectedSeguradora = new Seguradora();
+
+ public bool Apelido
+ {
+ get
+ {
+ return this._apelido;
+ }
+ set
+ {
+ this._apelido = value;
+ base.OnPropertyChanged("Apelido");
+ }
+ }
+
+ public bool? Ativo { get; set; } = new bool?(true);
+
+ public bool Carregando
+ {
+ get
+ {
+ return this._carregando;
+ }
+ set
+ {
+ this._carregando = value;
+ base.IsEnabled = !value;
+ base.OnPropertyChanged("Carregando");
+ }
+ }
+
+ public ObservableCollection<Imposto> Impostos
+ {
+ get
+ {
+ return this._impostos;
+ }
+ set
+ {
+ this._impostos = value;
+ base.OnPropertyChanged("Impostos");
+ }
+ }
+
+ public List<Ramo> Ramos
+ {
+ get
+ {
+ return this._ramos;
+ }
+ set
+ {
+ this._ramos = value;
+ base.OnPropertyChanged("Ramos");
+ }
+ }
+
+ public List<Seguradora> Seguradoras
+ {
+ get
+ {
+ return this._seguradoras;
+ }
+ set
+ {
+ this._seguradoras = value;
+ base.OnPropertyChanged("Seguradoras");
+ }
+ }
+
+ public Imposto SelectedImposto
+ {
+ get
+ {
+ return this._selectedImposto;
+ }
+ set
+ {
+ long? nullable;
+ this._selectedImposto = value;
+ if (value != null)
+ {
+ nullable = new long?(value.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ }
+ base.VerificarEnables(nullable);
+ base.OnPropertyChanged("SelectedImposto");
+ }
+ }
+
+ public Ramo SelectedRamo
+ {
+ get
+ {
+ return this._selectedRamo;
+ }
+ set
+ {
+ this._selectedRamo = value;
+ base.OnPropertyChanged("SelectedRamo");
+ }
+ }
+
+ public Seguradora SelectedSeguradora
+ {
+ get
+ {
+ return this._selectedSeguradora;
+ }
+ set
+ {
+ this._selectedSeguradora = value;
+ base.OnPropertyChanged("SelectedSeguradora");
+ }
+ }
+
+ private ImpostoServico Servico
+ {
+ get;
+ }
+
+ public ImpostoViewModel()
+ {
+ this.Servico = new ImpostoServico();
+ this.Apelido = Recursos.Configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 6);
+ }
+
+ public void AlterarImposto()
+ {
+ base.Alterar(true);
+ }
+
+ public async Task Cancelar()
+ {
+ long id;
+ Imposto selectedImposto = this.SelectedImposto;
+ if (selectedImposto != null)
+ {
+ id = selectedImposto.get_Id();
+ }
+ else
+ {
+ id = (long)0;
+ }
+ long num = id;
+ base.Alterar(false);
+ await this.Carregar(num);
+ }
+
+ public async Task Carregar(int tipo, long id)
+ {
+ string str;
+ this.Tipo = tipo;
+ await base.PermissaoTela(56);
+ List<Seguradora> list = Recursos.Seguradoras.Where<Seguradora>((Seguradora x) => {
+ if (x.get_Ativo())
+ {
+ return true;
+ }
+ if (tipo != 0)
+ {
+ return false;
+ }
+ return x.get_Id() == id;
+ }).OrderBy<Seguradora, string>((Seguradora x) => {
+ if (!this.Apelido)
+ {
+ return x.get_Nome();
+ }
+ return x.get_NomeSocial();
+ }).ToList<Seguradora>();
+ Seguradora seguradora = new Seguradora();
+ seguradora.set_Nome("TODAS SEGURADORAS");
+ seguradora.set_NomeSocial("TODAS SEGURADORAS");
+ seguradora.set_Id((long)0);
+ list.Insert(0, seguradora);
+ this.Seguradoras = list;
+ this.SelectedSeguradora = this.Seguradoras.First<Seguradora>();
+ IEnumerable<Ramo> ramos = Recursos.Ramos.Where<Ramo>((Ramo x) => {
+ if (x.get_Ativo())
+ {
+ return true;
+ }
+ if (tipo != 1)
+ {
+ return false;
+ }
+ return x.get_Id() == id;
+ });
+ List<Ramo> list1 = (
+ from x in ramos
+ orderby x.get_Nome()
+ select x).ToList<Ramo>();
+ Ramo ramo = new Ramo();
+ ramo.set_Nome("TODOS OS RAMOS");
+ ramo.set_Id((long)0);
+ list1.Insert(0, ramo);
+ this.Ramos = list1;
+ this.SelectedRamo = this.Ramos.First<Ramo>();
+ str = (tipo == 1 ? string.Concat("O RAMO \"", this.Ramos.First<Ramo>((Ramo x) => x.get_Id() == id).get_Nome(), "\"") : string.Concat("A SEGURADORA \"", this.Seguradoras.First<Seguradora>((Seguradora x) => x.get_Id() == id).get_Nome(), "\""));
+ string str1 = str;
+ base.RegistrarAcao(string.Concat("ACESSOU IMPOSTOS D", str1), id, new TipoTela?(56), string.Format("ID: {0}", id));
+ List<Imposto> impostos = await this.Servico.Buscar(new bool?(true));
+ if (tipo == 1)
+ {
+ impostos = impostos.Where<Imposto>((Imposto x) => {
+ if (x.get_Ramo() == null || x.get_Ramo().get_Id() != id)
+ {
+ return false;
+ }
+ return x.get_Seguradora() == null;
+ }).ToList<Imposto>();
+ this.SelectedRamo = this.Ramos.Find((Ramo x) => x.get_Id() == id);
+ }
+ else
+ {
+ impostos = impostos.Where<Imposto>((Imposto x) => {
+ if (x.get_Seguradora() == null || x.get_Seguradora().get_Id() != id)
+ {
+ return false;
+ }
+ return x.get_Ramo() == null;
+ }).ToList<Imposto>();
+ this.SelectedSeguradora = this.Seguradoras.Find((Seguradora x) => x.get_Id() == id);
+ }
+ ImpostoViewModel observableCollection = this;
+ List<Imposto> impostos1 = impostos;
+ observableCollection.Impostos = new ObservableCollection<Imposto>(
+ from x in impostos1
+ orderby x.get_Ativo() descending
+ select x);
+ this.SelectedImposto = this.Impostos.FirstOrDefault<Imposto>();
+ }
+
+ public async Task Carregar(long id = 0L)
+ {
+ Imposto imposto;
+ List<Imposto> list = await this.Servico.Buscar(this.Ativo);
+ if (this.SelectedSeguradora.get_Id() == 0)
+ {
+ List<Imposto> impostos = list;
+ list = (
+ from x in impostos
+ where x.get_Seguradora() == null
+ select x).ToList<Imposto>();
+ }
+ if (this.SelectedSeguradora.get_Id() > (long)0)
+ {
+ list = list.Where<Imposto>((Imposto x) => {
+ if (x.get_Seguradora() == null)
+ {
+ return false;
+ }
+ return x.get_Seguradora().get_Id() == this.SelectedSeguradora.get_Id();
+ }).ToList<Imposto>();
+ }
+ if (this.SelectedRamo.get_Id() == 0)
+ {
+ List<Imposto> impostos1 = list;
+ list = (
+ from x in impostos1
+ where x.get_Ramo() == null
+ select x).ToList<Imposto>();
+ }
+ if (this.SelectedRamo.get_Id() > (long)0)
+ {
+ list = list.Where<Imposto>((Imposto x) => {
+ if (x.get_Ramo() == null)
+ {
+ return false;
+ }
+ return x.get_Ramo().get_Id() == this.SelectedRamo.get_Id();
+ }).ToList<Imposto>();
+ }
+ this.Impostos = new ObservableCollection<Imposto>(list.Where<Imposto>((Imposto x) => {
+ if (!this.Ativo.HasValue)
+ {
+ return true;
+ }
+ return x.get_Ativo() == this.Ativo.Value;
+ }).ToList<Imposto>());
+ ImpostoViewModel impostoViewModel = this;
+ imposto = (id == 0 ? this.Impostos.FirstOrDefault<Imposto>() : this.Impostos.FirstOrDefault<Imposto>((Imposto x) => x.get_Id() == id));
+ impostoViewModel.SelectedImposto = imposto;
+ }
+
+ public void Incluir()
+ {
+ Seguradora selectedSeguradora;
+ Ramo selectedRamo;
+ Imposto imposto = new Imposto();
+ if (this.SelectedSeguradora.get_Id() > (long)0)
+ {
+ selectedSeguradora = this.SelectedSeguradora;
+ }
+ else
+ {
+ selectedSeguradora = null;
+ }
+ imposto.set_Seguradora(selectedSeguradora);
+ if (this.SelectedRamo.get_Id() > (long)0)
+ {
+ selectedRamo = this.SelectedRamo;
+ }
+ else
+ {
+ selectedRamo = null;
+ }
+ imposto.set_Ramo(selectedRamo);
+ imposto.set_Ativo(true);
+ this.SelectedImposto = imposto;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ string str;
+ string str1;
+ string str2;
+ object obj;
+ string str3;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedImposto.Validate();
+ keyValuePairs1.AddRange(this.Validate(this.SelectedImposto));
+ if (keyValuePairs1.Count <= 0)
+ {
+ str = (this.SelectedImposto.get_Id() == 0 ? "INCLUIU" : "ALTEROU");
+ str3 = str;
+ Imposto imposto = await this.Servico.Salvar(this.SelectedImposto);
+ if (this.Servico.Sucesso)
+ {
+ str1 = (imposto.get_Seguradora() == null ? "TODAS AS SEGURADORAS" : string.Concat(" SEGURADORA ", imposto.get_Seguradora().get_Nome()));
+ string str4 = str1;
+ str2 = (imposto.get_Ramo() == null ? "TODOS OS RAMOS" : string.Concat(" RAMO ", imposto.get_Ramo().get_Nome()));
+ string str5 = str2;
+ string str6 = string.Concat(" ", str4, " E ", str5);
+ ImpostoViewModel impostoViewModel = this;
+ string str7 = string.Concat(str3, " IMPOSTO PARA ", str6);
+ long id = imposto.get_Id();
+ TipoTela? nullable = new TipoTela?(31);
+ object[] ir = new object[] { imposto.get_Id(), str4, str5, null, null, null, null, null };
+ obj = (imposto.get_Ativo() ? "ATIVO" : "INATIVO");
+ ir[3] = obj;
+ ir[4] = imposto.get_Ir();
+ ir[5] = imposto.get_Iss();
+ ir[6] = imposto.get_Outros();
+ ir[7] = imposto.get_Desconto();
+ impostoViewModel.RegistrarAcao(str7, id, nullable, string.Format("ID: {0}{1}{2}\nSTATUS: {3}\nIR: {4:p2}\nISS: {5:p2}\nOUTROS: {6:p2}\nDESCONTO: {7:p2}", ir));
+ base.Alterar(false);
+ await this.Carregar(imposto.get_Id());
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = new List<KeyValuePair<string, string>>()
+ {
+ new KeyValuePair<string, string>("GRAVAR", "HOUVE UM ERRO AO SALVAR O IMPOSTO SELECIONADO.")
+ };
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ str3 = null;
+ return keyValuePairs;
+ }
+
+ public List<KeyValuePair<string, string>> Validate(Imposto imposto)
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ if (imposto == null)
+ {
+ return keyValuePairs;
+ }
+ if (imposto.get_Ativo() && this.Impostos.Any<Imposto>((Imposto x) => {
+ long? nullable;
+ long? nullable1;
+ long? nullable2;
+ long? nullable3;
+ long? nullable4;
+ if (x.get_Id() != imposto.get_Id())
+ {
+ Seguradora seguradora = x.get_Seguradora();
+ if (seguradora != null)
+ {
+ nullable1 = new long?(seguradora.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ nullable1 = nullable;
+ }
+ long? nullable5 = nullable1;
+ Seguradora seguradora1 = imposto.get_Seguradora();
+ if (seguradora1 != null)
+ {
+ nullable2 = new long?(seguradora1.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ long? nullable6 = nullable2;
+ if (nullable5.GetValueOrDefault() == nullable6.GetValueOrDefault() & nullable5.HasValue == nullable6.HasValue)
+ {
+ Ramo ramo = x.get_Ramo();
+ if (ramo != null)
+ {
+ nullable3 = new long?(ramo.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ nullable3 = nullable;
+ }
+ nullable6 = nullable3;
+ Ramo ramo1 = imposto.get_Ramo();
+ if (ramo1 != null)
+ {
+ nullable4 = new long?(ramo1.get_Id());
+ }
+ else
+ {
+ nullable = null;
+ nullable4 = nullable;
+ }
+ nullable5 = nullable4;
+ if (nullable6.GetValueOrDefault() == nullable5.GetValueOrDefault() & nullable6.HasValue == nullable5.HasValue)
+ {
+ return x.get_Ativo();
+ }
+ }
+ }
+ return false;
+ }))
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("IMPOSTO DUPLICADO", "NÃO É POSSIVEL INSERIR UM NOVO PARAMETRO DE IMPOSTO, POIS JÁ EXISTEM PARAMETROS PARA A MESMA SEGURADORA E RAMO"));
+ }
+ return keyValuePairs.Distinct<KeyValuePair<string, string>>().ToList<KeyValuePair<string, string>>();
+ }
+ }
+} \ No newline at end of file