diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Application/ViewModels/Generic/DialogEditarParcelasViewModel.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Gestor.Application/ViewModels/Generic/DialogEditarParcelasViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/Generic/DialogEditarParcelasViewModel.cs | 342 |
1 files changed, 0 insertions, 342 deletions
diff --git a/Gestor.Application/ViewModels/Generic/DialogEditarParcelasViewModel.cs b/Gestor.Application/ViewModels/Generic/DialogEditarParcelasViewModel.cs deleted file mode 100644 index bf96cfe..0000000 --- a/Gestor.Application/ViewModels/Generic/DialogEditarParcelasViewModel.cs +++ /dev/null @@ -1,342 +0,0 @@ -using Gestor.Application.Actions;
-using Gestor.Application.Helpers;
-using Gestor.Application.Servicos;
-using Gestor.Model.Common;
-using Gestor.Model.Domain.Configuracoes;
-using Gestor.Model.Domain.Generic;
-using Gestor.Model.Domain.Seguros;
-using Gestor.Model.Resources;
-using System;
-using System.Collections;
-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.Generic
-{
- public class DialogEditarParcelasViewModel : BaseViewModel
- {
- private List<Parcela> _parcelasOriginais;
-
- internal Gestor.Application.Servicos.ParcelaServico ParcelaServico;
-
- private ObservableCollection<Parcela> _parcelas;
-
- private bool _isFatura;
-
- private string _status;
-
- private Parcela _selectedParcela;
-
- private Documento _selectedDocumento;
-
- public bool IsFatura
- {
- get
- {
- return this._isFatura;
- }
- set
- {
- this._isFatura = value;
- base.OnPropertyChanged("IsFatura");
- }
- }
-
- public ObservableCollection<Parcela> Parcelas
- {
- get
- {
- return this._parcelas;
- }
- set
- {
- this._parcelas = value;
- base.OnPropertyChanged("Parcelas");
- }
- }
-
- public Documento SelectedDocumento
- {
- get
- {
- return this._selectedDocumento;
- }
- set
- {
- this._selectedDocumento = value;
- base.OnPropertyChanged("SelectedDocumento");
- }
- }
-
- public Parcela SelectedParcela
- {
- get
- {
- return this._selectedParcela;
- }
- set
- {
- this._selectedParcela = value;
- base.OnPropertyChanged("SelectedParcela");
- }
- }
-
- public string Status
- {
- get
- {
- return this._status;
- }
- set
- {
- this._status = value;
- base.OnPropertyChanged("Status");
- }
- }
-
- public DialogEditarParcelasViewModel(Documento documento)
- {
- this.SelectedDocumento = documento;
- this.ParcelaServico = new Gestor.Application.Servicos.ParcelaServico();
- this.Carregar(documento.get_Id());
- TipoRecebimento? tipoRecebimento = documento.get_TipoRecebimento();
- this.IsFatura = tipoRecebimento.GetValueOrDefault(1) == 2;
- }
-
- public void AlterandoValor()
- {
- if (this.SelectedParcela.get_Documento() == null)
- {
- this.SelectedParcela.set_Documento(this.SelectedDocumento);
- }
- this.SelectedParcela.get_Documento().set_Parcelas(this.Parcelas);
- if (this.SelectedDocumento.get_TipoRecebimento().GetValueOrDefault() == 1 && this.SelectedParcela.get_SubTipo() == 1 && this.SelectedParcela.get_Comissao() == decimal.Zero)
- {
- this.SelectedParcela.set_Comissao(this.SelectedDocumento.get_Comissao());
- }
- this.SelectedParcela.set_Baixando(false);
- this.AlterarValor();
- }
-
- public void AlterandoVencimento(Parcela parcela)
- {
- DateTime vencimento;
- ObservableCollection<Parcela> parcelas;
- if (Recursos.Configuracoes.All<ConfiguracaoSistema>((ConfiguracaoSistema y) => y.get_Configuracao() != 11))
- {
- DateTime? vigencia2 = parcela.get_Documento().get_Vigencia2();
- if (vigencia2.HasValue)
- {
- vencimento = parcela.get_Vencimento();
- vigencia2 = parcela.get_Documento().get_Vigencia2();
- if ((vigencia2.HasValue ? vencimento > vigencia2.GetValueOrDefault() : false) && parcela.get_Documento().get_Controle().get_Ramo().get_Id() != (long)23)
- {
- Action<string> acionarSnackbar = Gestor.Application.Actions.Actions.AcionarSnackbar;
- if (acionarSnackbar != null)
- {
- acionarSnackbar(string.Concat("DATA INVÁLIDA. ", Messages.get_VencimentoMaior()));
- }
- else
- {
- }
- parcela.set_Vencimento(this._parcelasOriginais.First<Parcela>((Parcela x) => x.get_Id() == parcela.get_Id()).get_Vencimento());
- }
- }
- }
- if (Recursos.Configuracoes.All<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() != 9))
- {
- if (parcela.get_Documento().get_Vigencia1() > DateTime.MinValue && parcela.get_NumeroParcela() == 1)
- {
- DateTime dateTime = parcela.get_Vencimento();
- vencimento = parcela.get_Documento().get_Vigencia1();
- if (dateTime < vencimento.AddDays(-30))
- {
- goto Label0;
- }
- }
- if (parcela.get_NumeroParcela() == 1 || !(parcela.get_Vencimento() < parcela.get_Documento().get_Vigencia1()))
- {
- parcelas = this.Parcelas;
- this.Parcelas = new ObservableCollection<Parcela>(
- from x in parcelas
- orderby x.get_NumeroParcela()
- select x);
- return;
- }
- Label0:
- Action<string> action = Gestor.Application.Actions.Actions.AcionarSnackbar;
- if (action != null)
- {
- action(string.Concat("DATA INVÁLIDA. ", Messages.get_VencimentoMenor()));
- }
- else
- {
- }
- parcela.set_Vencimento(this._parcelasOriginais.First<Parcela>((Parcela x) => x.get_Id() == parcela.get_Id()).get_Vencimento());
- }
- parcelas = this.Parcelas;
- this.Parcelas = new ObservableCollection<Parcela>(
- from x in parcelas
- orderby x.get_NumeroParcela()
- select x);
- }
-
- public void AlterarValor()
- {
- if (this.SelectedParcela == null)
- {
- return;
- }
- if (this.SelectedParcela.get_SubTipo() != 1 || this.IsFatura)
- {
- this.SelectedParcela.set_Documento(this.SelectedDocumento);
- return;
- }
- decimal premioTotal = this.SelectedDocumento.get_PremioTotal() - this.Parcelas.Where<Parcela>((Parcela x) => {
- if (x.get_SubTipo() != 1)
- {
- return false;
- }
- return x.get_Id() != this.SelectedParcela.get_Id();
- }).Sum<Parcela>((Parcela x) => x.get_Valor());
- decimal valor = this.SelectedDocumento.get_PremioTotal() - this.Parcelas.Where<Parcela>((Parcela x) => {
- if (x.get_SubTipo() != 1)
- {
- return false;
- }
- return x.get_Id() < this.SelectedParcela.get_Id();
- }).Sum<Parcela>((Parcela x) => x.get_Valor());
- valor -= this.SelectedParcela.get_Valor();
- decimal numeroParcelas = this.SelectedDocumento.get_NumeroParcelas() - this.SelectedParcela.get_NumeroParcela();
- if (numeroParcelas == decimal.Zero)
- {
- numeroParcelas = decimal.One;
- }
- decimal num = (numeroParcelas > decimal.Zero ? valor / numeroParcelas : decimal.Zero);
- if (num == decimal.Zero)
- {
- this.SelectedParcela.set_Valor(premioTotal);
- }
- List<Parcela> parcelas = new List<Parcela>()
- {
- this.SelectedParcela
- };
- decimal num1 = Math.Abs(num);
- decimal? tolerancia = this.SelectedDocumento.get_Controle().get_Seguradora().get_Tolerancia();
- if ((num1 > tolerancia.GetValueOrDefault()) & tolerancia.HasValue && !this.Parcelas.Any<Parcela>((Parcela x) => {
- if (x.get_SubTipo() != 1)
- {
- return false;
- }
- return x.get_NumeroParcela() > this.SelectedParcela.get_NumeroParcela();
- }))
- {
- this.SelectedParcela.set_Valor(premioTotal);
- }
- this.Parcelas.Where<Parcela>((Parcela x) => {
- if (x.get_SubTipo() != 1)
- {
- return false;
- }
- return x.get_NumeroParcela() != this.SelectedParcela.get_NumeroParcela();
- }).ToList<Parcela>().ForEach((Parcela x) => {
- if (x.get_NumeroParcela() > this.SelectedParcela.get_NumeroParcela())
- {
- x.set_Valor((num > decimal.Zero ? num : x.get_Valor()));
- x.set_Comissao((x.get_Comissao() == decimal.Zero ? this.SelectedDocumento.get_Comissao() : x.get_Comissao()));
- }
- parcelas.Add(x);
- });
- foreach (Parcela parcela in
- from x in parcelas
- where x.get_NumeroParcela() >= this.SelectedParcela.get_NumeroParcela()
- select x)
- {
- parcela.set_Documento(this.SelectedDocumento);
- if (parcela.get_Id() == this.SelectedParcela.get_Id())
- {
- continue;
- }
- parcela.set_Valor(num);
- }
- this.Parcelas = new ObservableCollection<Parcela>(
- from x in parcelas
- orderby x.get_NumeroParcela()
- select x);
- }
-
- public async void Carregar(long id)
- {
- await this.CarregarParcelas(id);
- }
-
- public async Task CarregarParcelas(long id)
- {
- ObservableCollection<Parcela> observableCollection;
- ObservableCollection<Parcela> observableCollection1 = await (new Gestor.Application.Servicos.ParcelaServico()).BuscarParcelasAsync(id);
- this._parcelasOriginais = new List<Parcela>();
- foreach (Parcela parcela in observableCollection1)
- {
- this._parcelasOriginais.Add((Parcela)parcela.Clone());
- }
- DialogEditarParcelasViewModel dialogEditarParcelasViewModel = this;
- if (this.IsFatura)
- {
- ObservableCollection<Parcela> observableCollection2 = observableCollection1;
- observableCollection = new ObservableCollection<Parcela>(
- from x in observableCollection2
- orderby x.get_NumeroParcela()
- select x);
- }
- else
- {
- observableCollection = observableCollection1;
- }
- dialogEditarParcelasViewModel.Parcelas = observableCollection;
- }
-
- public async Task<bool> SalvarParcelas()
- {
- bool flag;
- foreach (Parcela parcela in this.Parcelas)
- {
- Parcela parcela1 = this._parcelasOriginais.First<Parcela>((Parcela x) => x.get_Id() == parcela.get_Id());
- if (!(parcela.get_Vencimento() != parcela1.get_Vencimento()) && !(parcela.get_Valor() != parcela1.get_Valor()))
- {
- continue;
- }
- parcela1.set_Vencimento(parcela.get_Vencimento());
- parcela1.set_Valor(parcela.get_Valor());
- Parcela selectedParcela = this.SelectedParcela;
- List<ConfiguracaoSistema> configuracoes = Recursos.Configuracoes;
- bool flag1 = configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 9);
- List<ConfiguracaoSistema> configuracaoSistemas = Recursos.Configuracoes;
- bool flag2 = configuracaoSistemas.Any<ConfiguracaoSistema>((ConfiguracaoSistema y) => y.get_Configuracao() == 11);
- List<ConfiguracaoSistema> configuracoes1 = Recursos.Configuracoes;
- List<KeyValuePair<string, string>> keyValuePairs = selectedParcela.Validate(flag1, flag2, true, configuracoes1.Any<ConfiguracaoSistema>((ConfiguracaoSistema x) => x.get_Configuracao() == 16));
- if (keyValuePairs.Count <= 0)
- {
- await (new Gestor.Application.Servicos.ParcelaServico()).Save(parcela1, this._parcelasOriginais, null, true);
- }
- else
- {
- List<KeyValuePair<string, string>> keyValuePairs1 = keyValuePairs;
- string str = string.Join(", ", keyValuePairs1.Select<KeyValuePair<string, string>, string>((KeyValuePair<string, string> x) => {
- string[] strArrays = x.Key.Split(new char[] { '|' });
- return string.Concat(((int)strArrays.Length > 1 ? strArrays[1] : x.Key), ": ", x.Value, Environment.NewLine);
- }));
- this.Status = string.Concat("NÃO FOI POSSÍVEL SALVAR DEVIDO AOS ERROS ABAIXO:", Environment.NewLine, str);
- flag = false;
- return flag;
- }
- }
- base.RegistrarAcao(string.Format("EDITOU VENCIMENTO E/OU VALORES DAS PARCELAS/FATURAS DO DOCUMENTO DE ID {0}", this.Parcelas[0].get_Documento().get_Id()), this.Parcelas[0].get_Documento().get_Id(), new TipoTela?(5), null);
- flag = true;
- return flag;
- }
- }
-}
\ No newline at end of file |