summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Seguros/ApoliceViewModel.cs
blob: 94fc4be7a707746bbce20140da1e3da08fa7e4e4 (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
using Gestor.Application.Drawers;
using Gestor.Application.Helpers;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Common;
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.Seguros
{
	public class ApoliceViewModel : BaseApoliceViewModel
	{
		private bool _documentoExcluido;

		public bool DocumentoExcluido
		{
			get
			{
				return this._documentoExcluido;
			}
			set
			{
				this._documentoExcluido = value;
				base.OnPropertyChanged("DocumentoExcluido");
			}
		}

		public ApoliceViewModel(AcessoApolice acesso, Documento documentoSelecionado, bool invoke = true, long idparcela = 0L)
		{
			long id;
			base.Invoke = invoke;
			base.Acesso = acesso;
			base.DocumentoSelecionado = documentoSelecionado;
			if (invoke)
			{
				Parcela parcelaSelecionada = ConsultaViewModel.ParcelaSelecionada;
				if (parcelaSelecionada != null)
				{
					id = parcelaSelecionada.get_Id();
				}
				else
				{
					id = (long)0;
				}
			}
			else
			{
				id = idparcela;
			}
			base.ParcelaSelecionada = id;
			this.DocumentoExcluido = (base.DocumentoSelecionado != null ? base.DocumentoSelecionado.get_Excluido() : false);
			base.Seleciona(base.DocumentoSelecionado);
		}

		public void AbrirInfo()
		{
			base.ShowDrawer(new InfoDrawer(base.SelectedDocumento, true), 0, false);
		}

		public async Task Alteracao(bool alterar)
		{
			if (base.AllowEditApolice)
			{
				ObservableCollection<Parcela> parcelas = base.Parcelas;
				if (!parcelas.Any<Parcela>((Parcela x) => x.get_DataRecebimento().HasValue))
				{
					List<VendedorParcela> repasses = base.Repasses;
					if (!repasses.Any<VendedorParcela>((VendedorParcela x) => x.get_DataPagamento().HasValue))
					{
						List<Seguradora> list = Recursos.Seguradoras.Where<Seguradora>((Seguradora x) => {
							if (x.get_Ativo())
							{
								return true;
							}
							return x.get_Id() == base.SelectedDocumento.get_Controle().get_Seguradora().get_Id();
						}).ToList<Seguradora>();
						base.Seguradoras = list;
						base.SeguradorasAnteriores = Recursos.Seguradoras;
						List<Ramo> ramos = Recursos.Ramos.Where<Ramo>((Ramo x) => {
							if (x.get_Ativo())
							{
								return true;
							}
							return x.get_Id() == base.SelectedDocumento.get_Controle().get_Ramo().get_Id();
						}).ToList<Ramo>();
						base.Ramos = ramos;
						List<Produto> produtos = Recursos.Produtos.Where<Produto>((Produto x) => {
							if (x.get_Ativo())
							{
								return true;
							}
							if (base.SelectedDocumento.get_Controle().get_Produto() == null)
							{
								return false;
							}
							return x.get_Id() == base.SelectedDocumento.get_Controle().get_Produto().get_Id();
						}).ToList<Produto>();
						base.Produtos = produtos;
						List<Gestor.Model.Domain.Seguros.Status> statuses = Recursos.Status.Where<Gestor.Model.Domain.Seguros.Status>((Gestor.Model.Domain.Seguros.Status x) => {
							if (x.get_Ativo())
							{
								return true;
							}
							if (base.SelectedDocumento.get_Status() == null)
							{
								return false;
							}
							return x.get_Id() == base.SelectedDocumento.get_Status().get_Id();
						}).ToList<Gestor.Model.Domain.Seguros.Status>();
						base.Status = statuses;
						return;
					}
				}
			}
			await base.ShowMessage("DOCUMENTO POSSUI BAIXAS DE COMISSÃO OU PAGAMENTO DE VENDEDORES.\nNÃO SERÁ POSSÍVEL ALTERAR ALGUMAS INFORMAÇÕES DO DOCUMENTO.\nPARA ISSO, EXCLUA AS BAIXAS E O PAGAMENTO DO VENDEDOR", "OK", "", false);
		}
	}
}